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

1 vue (au cours des 30 derniers jours)
marios semer
marios semer le 7 Déc 2020
Commenté : marios semer le 7 Déc 2020
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!

Réponse acceptée

David Hill
David Hill le 7 Déc 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 commentaire
marios semer
marios semer le 7 Déc 2020
It worked mate. It seems you made it work without understanding XD. Thank you so much.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by