How to load numbers in my array through a while true loop ?

1 Ansicht (letzte 30 Tage)
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!

Akzeptierte Antwort

David Hill
David Hill am 7 Dez. 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
  1 Kommentar
marios semer
marios semer am 7 Dez. 2020
It worked mate. It seems you made it work without understanding XD. Thank you so much.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by