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)
  1 件のコメント
afrya
afrya 2013 年 12 月 10 日
Thank you for your answer

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by