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?

 Risposta accettata

Image Analyst
Image Analyst il 18 Ott 2021
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 Commenti

Nicle Davidson
Nicle Davidson il 19 Ott 2021
no, this does not have a fix on the problem as the out put comes as
13×8 char array
' mmn '
' iio '
' nn '
' io '
' y'
' '
' '
Image Analyst
Image Analyst il 19 Ott 2021
@Nicle Davidson, you didn't answer my questions:
"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?"
I'd like to see the answer to that, along with your uploaded words.txt, before I spend ony more time for you.
Nicle Davidson
Nicle Davidson il 19 Ott 2021
Home work.
Nicle Davidson
Nicle Davidson il 19 Ott 2021
I have written the code write as the matrix looks ok. But the twist which makes the words stay wrong place is the problem only. it is explained in the case. I appreciate you time and effort.
Image Analyst
Image Analyst il 19 Ott 2021
I'm confused as to what you want. I read in the words and displayed them on a slant. Is that not what you want? I don't understand all your red arrows in your diagram. Post an array of your desired output.
Nicle Davidson
Nicle Davidson il 19 Ott 2021
Ok, my desired output should look like this>
your see here the row numbers and collumn numbers. however they will not be on the output. I kept them here just to show what I meen. These row and column numbers are states. we go from state 1 to 2. From 2 to 3. From state 1 to 8 and from 8 to 9. The reason no starts to register in (1,8) is that it does not start with m, this is a new word. so n starts in row 1 but should be column 8 because column 7 is used. then o should be placed in (8,9), so n in (1,8) and o in (8,9).
You see,
minoy however had the same start as mini, but it had to register a branch where o came and continue, however, as o stayed in (4,6) then y had to stay in (6,7). and y should be capital as the word minoy ends with y.
my program works well, but the problem is it puts y in row 5 and it should stay at row 6, does it explain better?
Image Analyst
Image Analyst il 20 Ott 2021
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.
Nicle Davidson
Nicle Davidson il 5 Nov 2021
I will thank you for your effort and accept this answer.

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by