place after the plan
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a file with some words, I read from this file. Inside the file there I have 3 words. 'mini', 'minoy', 'no' each in one line. (could also be more than 3 words in my file, but one word per line.)
inList = fopen('words.txt');
wd= fgetl(inList);
I read the words line by line and make a matrix of it H.
1.In this matrix same words should go same paths, but make branch where the words gets different
such as the word mini and minoy, where the first word mini fills the 0 places, because first time we register a word in a matrix of only 0's, then the secon word that has the same part 'min' same as mini, will go same path until it comes to I, then it makes its next word beside 'I' (which is made to capital word because the last letter of each word to be capital), so 'i' is set to 'I', and o from minoy sits in the cell beside I, and as o stands in H(4,6) as I was in H(4,5) and then last letter of minoy, which is y, should become capital and stand in H(6,7) because the letter before it (o) stays in H(4,6). But my program has a problem.
m stands in H(1,2), i stands in H(2,3), n stands in H(3,4), o stands in H(4,6) -> because I tok the place H(4,5), until here all good, but Y stands in H(5,6) however it should stand in H(6,7). Because the word o which was before y in minoy stands in H(4,6). It should be a kind of H(4,6) then H(6,7). Should be:(1,2),(2,3), (3,4),(4,6), (6,7) for minoy. But is: (1,2),(2,3), (3,4),(4,6), (5,6)
H= zeros(13,13);
j=1;
s=1;
i=0;
while ischar(wd)
for i=1:length(wd)
j=j+1;
s=s+1;
if H(i,s)~=wd(i)
H(i,j)=wd(i);
else
for k=1:length(wd)
if H(k,s)~=wd(k)
s=s+1;
H(k,s)=wd(k);
else
s=s+1;
end
end
H(k,s)=H(k,s)-32;
end
end
H(i,j)=H(i,j)-32;
wd = fgetl(inList);
s=1;
end
H=char(H);
What I get from my matrix H is this
2. Another thing I wold like to fix in this program is that i,n,o,Y which has repeated itself again, should not appear again, because they find their way in the first registration I did.
3. The last fix need to get in my program is on the third word 'no', because as no does not start with m, so it should start it's own path, from row 1. but (if we fix the second fix on this program, I think it will move automatically to its right place. However 'o' in 'no' should also stay in right place as 'n' should actually stay in H(1,7), then 'o' belonging to 'no' should stay in H(7,8)
like:
I think this is a little fix using one of the variables somewhere doing a pluss or something, I am struggling testing this to fix. Need some help if any one understood where the fix is.
*by the way first column is empty, and will be. but first row is for starting all new start of words.
Any better way to program this, or do the fix?
댓글 수: 0
채택된 답변
Image Analyst
2021년 10월 18일
Give us some context as to why you need this quirky thing. Like is it homework or is there some real world need? What is the use case?
Do you mean something like this:
allChars = fileread("CMUwords.txt");
allWords = unique(strsplit(allChars, '\r\n'))
numWords = numel(allWords)
numRows = 13;
H = char(zeros(numRows, numWords))
for col = 1 : length(allWords)
thisWord = allWords{col};
if isempty(thisWord)
continue;
end
for row = 1 : min([numRows, length(thisWord)])
% Load characters of the word in starting at column col and going down at a slant to the right.
H(row, col+row) = thisWord(row);
end
end
H
댓글 수: 8
Image Analyst
2021년 10월 20일
Sorry - it makes my head spin. Maybe someone else will understand.
I'm sure if you understand what's going on and you step through it with the debugger you'll figure out what's going wrong.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!