I Would like to create a variable array based upon user inputs.
1 回表示 (過去 30 日間)
古いコメントを表示
I have a variable that the user inputs called Type allocated as such:
n=input('How many measurements are you determining uncertainty upon? ');
Type=size(n)';
Uo=1;
while Uo<=n;
if Uo==1;
Type(Uo)=input('What type of measurement is your first measurement? (Input 1,2,or 3 for Pressure,Temperature, and Flow Rate Respectively) ');
Uo=Uo+1;
elseif Uo>1;
Type(Uo)=input('What type of measurement is your next measurement? (Input 1,2,or 3 for Pressure,Temperature, and Flow Rate Respectively) ');
Uo=Uo+1;
end
end
I would like to use these values to create another variable matrix later in my code. I tried the following:
Factor=cell(n:1)
for iter = 1:n
if Type == 1
Factor{iter}=1
elseif Type == 2
Factor{iter}=1
elseif Type ==3
Factor{iter}= 4
elseif Type < 1
break
elseif Type > 3
break
end
end
Could someone shine some light into what I am doing wrong here? or is there a far better method I should be using to do this?
Thanks ahead of time for any help you can lend!
3 件のコメント
採用された回答
Jan
2019 年 1 月 29 日
The code contains several strange commands.
Type=size(n)'
Are you sure? Without an explanation in the comment the readers can only guess, what you want. The question "How many ..." sound like you expect a scalar input, e.g. 5. Then size(5) replies [1,1] and transposing this is [1;1].
Later you fill the elements 1 to n of Type.
Factor=cell(n:1)
Do you mean:
Factor=cell(n, 1)
n:1 is the vector from n to 1, so most likely a scalar, if n>1. Then you create a {n x n} cell matrix.
When Type is a vector, them command if Type == 3 might not do, what you expect. if requires a scalar condition, therefore an all() is inserted implicitly. I guess you mean:
if Type(iter) == 3
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!