How to solve a problem in a user friendly program?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Jos (10584)
le 10 Déc 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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Function Creation 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!