How to load numbers in my array through a while true loop ?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
David Hill
2020-12-7
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!