필터 지우기
필터 지우기

how to read text file into matrix format in matlab.

조회 수: 1 (최근 30일)
Jothi
Jothi 2013년 6월 8일
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
Walter Roberson
Walter Roberson 2013년 6월 8일
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
Jothi 2013년 6월 8일
That's correct sir, the second row, the no. of times the word appears for the first sentence. for example the word this is appeared one time, is is appeared one time, very is appeared two times and so on. similarly, the row third is second sentence in the text file.
How to find it sir,

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2013년 6월 8일
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
Jothi
Jothi 2013년 6월 8일
Sir,
your printing the above matrix.
But, i want read the text file and then compute the above matrix.
thanks.
Walter Roberson
Walter Roberson 2013년 6월 8일
We are not going to do your entire assignment for you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by