I am new to Matlab and I am having trouble with all of the following (I have no
ID: 3786293 • Letter: I
Question
I am new to Matlab and I am having trouble with all of the following (I have no idea how to use these functions properly)
2. Read in the lines of a text file, e.g. your HW1 submission, using the fgetl function. Store the lines ofthis file in a cell array. Useful functions: for, fopen, fgetl.
3. Parse your stored lines of text into their constituent words using the strtok function. Store all of the words in the entire document in a cell array with one word per index.
4. Create a lexicon consisting of all of the unique words in the document. Useful function: unique.
5. Create a column vector representing how many times each lexicon word occurs in the document; Thisis a word vector representation for the document. Useful function: zeros.
Explanation / Answer
clc;
clear all;
% Read Data From Text File and Create a Cell arrray to store it.
fid = fopen('text1.log'); % Open the file from which you need to read
tline = fgets(fid); %open file handles
i=1;
while ischar(tline) % Reading each line from text file
data_line(i)={tline}; % storing each line into a cell
tline = fgets(fid); % Read next line
i=i+1;
end
fclose(fid); % close file
% Split sentences into words
j=1;
for i=1:size(data_line,2)
remain=data_line(i);
for k = 1:numel(strsplit(char(remain(1))))-1; % total number of words
[words(j), remain] = strtok(remain); % find a word from the text line
j=j+1;
end
end
% Find out the unique words in the word array
[unique_words,a,b]=unique(words); % find out all the unique words
% Findout Frequency of Occurance of a word
for i=1:numel(a)
final_occurance_mat(i,1)=unique_words(i);
final_occurance_mat(i,2)={sum(b==i)}; % calcualtion of frequency of occurance
end
disp(final_occurance_mat);
------------------------------------------------------------------------------------------------------------------------------------------------
% Input Text File
Release 14.2 - ngc2edif P.28xd (nt)
Copyright (c) 1995-2012 Xilinx, Inc. All rights reserved.
Reading design ICON_APUF.ngc ...
WARNING:NetListWriters:298 - No output is written to ICON_APUF.xncf, ignored.
Processing design ...
Preping design's networks ...
Preping design's macros ...
WARNING:NetListWriters:306 - Signal bus U0/U_ICON/iCORE_ID_SEL<15 : 0> on block
ICON_APUF is not reconstructed, because there are some missing bus signals.
finished :Prep
Writing EDIF netlist file ICON_APUF.edif ...
ngc2edif: Total memory usage is 62440 kilobytes
Release 14.2 - ngc2edif P.28xd (nt)
Copyright (c) 1995-2012 Xilinx, Inc. All rights reserved.
Reading design VIO_APUF.ngc ...
WARNING:NetListWriters:298 - No output is written to VIO_APUF.xncf, ignored.
Processing design ...
Preping design's networks ...
Preping design's macros ...
finished :Prep
Writing EDIF netlist file VIO_APUF.edif ...
ngc2edif: Total memory usage is 63464 kilobytes
-------------------------------------------------------------------------------------------------------------------------------------------------
% Output
'' [ 9]
'(c)' [ 2]
'(nt)' [ 2]
'-' [ 5]
'...' [10]
'0>' [ 1]
'14.2' [ 2]
'1995-2012' [ 2]
'62440' [ 1]
'63464' [ 1]
':' [ 1]
':Prep' [ 2]
'All' [ 2]
'Copyright' [ 2]
'EDIF' [ 2]
'ICON_APUF' [ 1]
'ICON_APUF.edif' [ 1]
'ICON_APUF.ngc' [ 1]
'ICON_APUF.xncf,' [ 1]
'Inc.' [ 2]
'No' [ 2]
'P.28xd' [ 2]
'Preping' [ 4]
'Processing' [ 2]
'Reading' [ 2]
'Release' [ 2]
'Signal' [ 1]
'Total' [ 2]
'U0/U_ICON/iCORE_ID_SEL<15' [ 1]
'VIO_APUF.edif' [ 1]
'VIO_APUF.ngc' [ 1]
'VIO_APUF.xncf,' [ 1]
'WARNING:NetListWriters:298' [ 2]
'WARNING:NetListWriters:306' [ 1]
'Writing' [ 2]
'Xilinx,' [ 2]
'are' [ 1]
'because' [ 1]
'block' [ 1]
'bus' [ 2]
'design' [ 4]
'design's' [ 4]
'file' [ 2]
'finished' [ 2]
'ignored.' [ 2]
'is' [ 5]
'kilobytes' [ 2]
'macros' [ 2]
'memory' [ 2]
'missing' [ 1]
'netlist' [ 2]
'networks' [ 2]
'ngc2edif' [ 2]
'ngc2edif:' [ 2]
'not' [ 1]
'on' [ 1]
'output' [ 2]
'reconstructed,' [ 1]
'reserved.' [ 2]
'rights' [ 2]
'signals.' [ 1]
'some' [ 1]
'there' [ 1]
'to' [ 2]
'usage' [ 2]
'written' [ 2]
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.