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!