View Full Version : one more matlab
zhupolongjoe
22 Feb 2009, 10:32pm
/////
shwaip
22 Feb 2009, 10:44pm
well, do you ever assign a value to lengthwords (which is what is returned by your fuction)?
zhupolongjoe
22 Feb 2009, 10:52pm
Ok:
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);
shwaip
23 Feb 2009, 12:14am
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).
zhupolongjoe
23 Feb 2009, 12:54am
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.
zhupolongjoe
23 Feb 2009, 3:41am
.............
shwaip
23 Feb 2009, 6:05pm
explain to me how you're trying to solve this problem, in psuedocode ie:
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.
vBulletin® v3.8.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.