function lengthwords=wordLengths(line)
spaces=findstr(' ', line);
index=-1; while index~=spaces;
index==index+1
lengthwords=index(line); return
end
end
I get error:
??? Index exceeds matrix dimensions.
Error in ==> wordLengths at 6
lengthwords=index(line);
You need to spend time reviewing basic programming concepts. In the three threads you've posted, your code starts out almost completely incorrect, with mistakes that you should have picked up via error messages that matlab gives you.
In this question, you clearly aren't understanding how:
a) indexing works
b) matlab indexing works.
when you say:
lengthwords=index(line);
You're trying to use line (which is a string) to index into the variable index (which is a scalar).
Jeez..I can't wait till this class ends so I can delete Matlab from my computer forever and snap the disk in half....I ace 400 level, proof-based math courses, but this 100 level computer science course is the bane of my existence.
Comments
function lengthwords=wordLengths(line)
spaces=findstr(' ', line);
index=-1;
while index~=spaces;
index==index+1
lengthwords=index(line);
return
end
end
I get error:
??? Index exceeds matrix dimensions.
Error in ==> wordLengths at 6
lengthwords=index(line);
In this question, you clearly aren't understanding how:
a) indexing works
b) matlab indexing works.
when you say:
lengthwords=index(line);
You're trying to use line (which is a string) to index into the variable index (which is a scalar).
step 1: find the locations of the spaces, using findstr();
.
.
.
this doesn't have to be anything that will work at all in matlab, just to give me an idea of how to help you.
After you've written the pseudocode, then see if your code matches up with it at all.