how to allow empty inputs in for loop?

3 ビュー (過去 30 日間)
Arry Rahmadi
Arry Rahmadi 2014 年 1 月 7 日
編集済み: Arry Rahmadi 2014 年 1 月 7 日
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.

採用された回答

ES
ES 2014 年 1 月 7 日
編集済み: ES 2014 年 1 月 7 日
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
  1 件のコメント
Arry Rahmadi
Arry Rahmadi 2014 年 1 月 7 日
編集済み: Arry Rahmadi 2014 年 1 月 7 日
Thanks a lot, choclate warrior! It works. Don't mind my previous comment. I get it now. Again. Thanks

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by