From: Mario Fatafehi on 25 Mar 2010 06:02 Can someone tell me what is wrong with my code below? Matlab gives me an error saying I can't do the assignment in the while loop. x = -2:0.1:2; y = x -1; while (-1=<x) & (x<=1) plot(x,y) end
From: mat001 on 25 Mar 2010 06:30 "Mario Fatafehi" <coruba9(a)hotmail.com> wrote in message <hofcat$dvg$1(a)fred.mathworks.com>... > Can someone tell me what is wrong with my code below? Matlab gives me an error saying I can't do the assignment in the while loop. > > x = -2:0.1:2; > y = x -1; > while (-1=<x) & (x<=1) > plot(x,y) > end okey try this x = -2:0.1:2; y = x -1; while (-1<=x) & (x<=1) plot(x,y) end
From: mat001 on 25 Mar 2010 06:32 "Mario Fatafehi" <coruba9(a)hotmail.com> wrote in message <hofcat$dvg$1(a)fred.mathworks.com>... > Can someone tell me what is wrong with my code below? Matlab gives me an error saying I can't do the assignment in the while loop. > > x = -2:0.1:2; > y = x -1; > while (-1=<x) & (x<=1) > plot(x,y) > end read Operator
From: Steven Lord on 25 Mar 2010 09:29 "Mario Fatafehi" <coruba9(a)hotmail.com> wrote in message news:hofcat$dvg$1(a)fred.mathworks.com... > Can someone tell me what is wrong with my code below? Matlab gives me an > error saying I can't do the assignment in the while loop. > > x = -2:0.1:2; > y = x -1; > while (-1=<x) & (x<=1) > plot(x,y) > end Then either: 1) You've shadowed the built-in PLOT function with your own version, or 2) There's some code in the WHILE loop that you didn't include in your post. Otherwise, there is no assignment being performed inside the loop in the code you posted. But you should be careful ... WHILE behaves in much the same way as IF when given a nonscalar expression. http://www.mathworks.com/access/helpdesk/help/techdoc/ref/while.html So if ALL the elements of x were between -1 and 1 inclusive (which they're not) you'd enter the loop ... and since x never changes inside the loop, the condition would always be true. So you'd be stuck in an infinite loop. Luckily, the way you've defined x, the condition is false for at least one of the elements of x, so you should never enter the loop. So if you're seeing the loop body execute and throw an error, there's some code you haven't showed to the group. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: fprintf - save string vector and scalar vector to a file Next: abt rbfnn |