How to solve a problem in a user friendly program?

조회 수: 3 (최근 30일)
afrya
afrya 2013년 12월 10일
댓글: afrya 2013년 12월 10일
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

채택된 답변

Jos (10584)
Jos (10584) 2013년 12월 10일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by