Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: Need help 'while' loop, a data set is given?

$
0
0
On 4/28/2013 2:50 AM, J K wrote:
...

> C1=input('Enter the value of C1: ');
> C2=input('Enter the value of C2: ');
>
> if C2==0
> fprintf('it is V belt \n');
> F=m*a;
> while C2==0
> d(find(F<=Fc,'1','first'));
> end
> end
>
...

> The problem that I get is the command window cannot execute the while
> loop. It shows 'it is V belt'. Then the command window will not respond
> to you.


...

No, the problem is it _DOES_ execute the WHILE; you've made an infinite
loop. As there's nothing inside the WHILE...END that will ever change
the value of C2, the condition C2==0 if true to be in the IF to begin
with will never, ever become false.

As seen above, you don't need WHILE at all to solve the problem, the
search across the values of your vector is being done by FIND
automagically--that's the point of using it.

doc while
doc find

doc matlab % right under the big red 'MATLAB' press "Getting Started"

--

Viewing all articles
Browse latest Browse all 19628

Trending Articles