how to allow empty inputs in for loop?
3 views (last 30 days)
Show older comments
Hi everyone. I am trying to make a script that takes inputs to calculate thermal resistance of composite walls. I want the script to be able to take empty inputs and replace them with zeros without changing the size of the input matrix, if some of the data are not available. Here's what I tried:
no_plt = input('number of plate =');
A = input('frontal area of plate =');
if isempty(A)
A = 1;
end
k = zeros(1,no_plt);
x = zeros(1,no_plt);
if no_plt == 1
k = input('plate conductivity =');
x = input('plate thickness =');
else
for m = 1:no_plt
k(m) = input (sprintf('conductivity of plate %d =',m));
if isempty (k(m))
k(m) = 0;
end
x(m) = input (sprintf('thickness of plate %d =',m));
if isempty (x(m))
x(m) = 0;
end
end
end
And it failed miserably. Here's the error I got:
In an assignment A(I) = B, the number of elements in B and I must be the same.
I read a very similiar question asked in this forum, but somehow it couldn't help me. And I am not sure I understand the solution either :). Could someone point out where my mistakes are, and explain it to me? I am new to matlab, so please go easy on me if the mistakes are obvious. Thanks in advance.
0 Comments
Accepted Answer
ES
on 7 Jan 2014
Edited: ES
on 7 Jan 2014
In short you cannot do a(1)=[]; where as you can do a temp=[];
try this...
no_plt = input('number of plate =');
A = input('frontal area of plate =');
if isempty(A)
A = 1;
end
k = zeros(1,no_plt);
x = zeros(1,no_plt);
if no_plt == 1
k = input('plate conductivity =');
x = input('plate thickness =');
else
for m = 1:no_plt
temp1 = input (sprintf('conductivity of plate %d =',m));
if isempty (temp1)
k(m) = 0;
else
k(m) = temp1;
end
temp2 = input (sprintf('thickness of plate %d =',m));
if isempty (temp2)
x(m) = 0;
else
x(m)=temp2;
end
end
end
More Answers (0)
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!