vendredi 3 septembre 2021

Octave: How to correctly make string as a condition?

a real beginner here.

Anyway, I was trying if test for the first time, well actually so does with function.

Here's the script:

function trial()
  I = input("f INPUT > Manually input frequency value? (yes/no):");
  if I = "yes"; 
    f = input("Please input the frequency value : \n") 
  elseif I = "no";
    f = randi([100 1000],5,5)
  endif
O = 2*pi*f;
fprintf("%.2f \n",O); 
plot(f,O);
xlabel("Frequency");
ylabel("Angular Frequency");
end
    f INPUT > Manually input frequency value? (yes/no):"no"
    Please input the frequency value :

there are 2 things that I don't understand:

  1. why do I have to write the condition with quotation marks? (i.e "yes" not yes or "no" not no)
  2. why the 'no' condition run the input command when it should've been randi?

Can someone show me how it should be done?

PS. Please go easy on me:)

Aucun commentaire:

Enregistrer un commentaire