How to solve a problem in a user friendly program?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear all, I have a problem with the folllowing user friendly program.
%AVkam=[1;2;3;4;5;6;7;8] %m=number of averages %n=total number of averages a=size(AVkam);
n=a(1,1)
m=input('Hello, enter the number of averages : ');
if m<=0 display('error, enter again a number of averages')
elseif m>n
display('error, enter again a number of averages')
elseif m<=n
b=n/m;
%%%%%%%%%make the smaller integer%%%%%
c=floor(b)
nurow=n-c*m
NewAVkam=AVkam(1:n-nurow,:)
Result=(1:c)
end
for i=1:c
nvk(i,1)=sum(NewAVkam(1+(i-1)*m:m*i,1),1)./m;
end
nvk
Problem: when I enter a negative value or a value which is higher than n, i get this message Undefined function or variable 'c'.
Undefined function or variable 'c'.
Error in tesuser1 (line 44) for i=1:c
What I want in my program is that the user re enter a value till this value is lower than n.Do you kow how can I solve this problem?
Thanks in advance
0 Commenti
Risposta accettata
Jos (10584)
il 10 Dic 2013
Use a WHILE loop. This example may get you started.
isOK = false ;
while ~isOK
A = input('Give a number: ')
if A < 0
disp('Error: it should be larger than zero')
elseif A >= 10
disp('Error: it should be smaller than 10')
else
isOK = true ;
end
end
disp(A)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Function Creation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!