How to load numbers in my array through a while true loop ?
1 view (last 30 days)
Show older comments
Hello, I want to add in my array ( w ) any numbers( between ( 0 , pi ) ) the user will give until he presses anything else to break the while true loop. What am i doing wrong in my code and:
Firstly it does not stop by giving anything else, and secondly the number I give do not append in my w list.
K = 26
w = linspace ( 0 , pi , 10*K );
a = '~';
while true;
a = input('Do you want to add a frequency ? (y/n) ——>','s');
if not(a == 'y')
break;
elseif strcmpi(a,'y')
while true;
number = input('Put a number between (0,π): ' , 's');
if isnan(number) || fix(number) ~= number
break;
elseif number < pi
number = input('Put a number between (0,π) again if you want: ' , 's');
w = [ w , str2num(number) ];
else
disp('Number is bigger than π. Please choose again:' );
end
end
end
end
Thank you for your help!
0 Comments
Accepted Answer
David Hill
on 7 Dec 2020
Not sure what you want to do. I guessed.
K = 26
w = linspace ( 0 , pi , 10*K );
while true
a = input('Do you want to add a frequency ? (y/n) ——>','s');
if ~isequal(a,'y')
break;
else
while true;
number = input('Add a frequency between (0,π): ');
if isnan(number) || number>=pi || number<=0
disp('Your frequency is not between (0,π)');
else
w = [ w , number ];
break;
end
end
end
end
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!