how to read text file into matrix format in matlab.
Show older comments
Sir,
I have a text file contains 2 sentences,
This is very very nice picture.
The picture quality is nice.
I want this file into following matrix format. the header line is all the common words in the text file. In the second line each sentence how many times appears in each word.
the output matrix is,
This is very nice picture the quality
1 1 2 1 1 0 0
0 1 0 1 1 1 1
how get this output using matlab.
thanks in advance.
3 Comments
Chandrasekhar
on 8 Jun 2013
I couldn't understand the question properly. Can u pls explain it.
1st row contains the sentence removing the duplicate words. I`m not able to understand 2nd row and 3rd row of the output matrix
Walter Roberson
on 8 Jun 2013
One output row for each sentence, it appears to me. The numbers are the number of times the word above the number appears in the sentence. There are two "very" in the first sentence so the first output has "2" in the output column for "very"
Jothi
on 8 Jun 2013
Answers (1)
Walter Roberson
on 8 Jun 2013
strs = {'This', 'is', 'very', 'nice', 'picture', 'the', 'quality'};
vals - [1 1 2 1 1 0 0; 0 1 0 1 1 1 1];
fprintf('%4s', strs{:});
fprintf('\n');
fprintf('%4d', vals(1,:))
fprintf('\n');
fprintf('%4d', vals(2,:))
fprintf('\n');
4 Comments
Chandrasekhar
on 8 Jun 2013
the sentences has to be read from the .txt file. then its has to be divided into rows and columns
Walter Roberson
on 8 Jun 2013
The difficult part of the Question is the "how to get this output", and that is the part I answered. There are a lot of examples around about how to read inputs from files, but there are not many examples around about how to present results in aligned tables.
Jothi
on 8 Jun 2013
Walter Roberson
on 8 Jun 2013
We are not going to do your entire assignment for you.
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!