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

1 visualización (últimos 30 días)
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!

Respuesta aceptada

David Hill
David Hill el 7 de Dic. de 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 comentario
marios semer
marios semer el 7 de Dic. de 2020
It worked mate. It seems you made it work without understanding XD. Thank you so much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by