how to allow empty inputs in for loop?

3 visualizzazioni (ultimi 30 giorni)
Arry Rahmadi
Arry Rahmadi il 7 Gen 2014
Modificato: Arry Rahmadi il 7 Gen 2014
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.

Risposta accettata

ES
ES il 7 Gen 2014
Modificato: ES il 7 Gen 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
  1 Commento
Arry Rahmadi
Arry Rahmadi il 7 Gen 2014
Modificato: Arry Rahmadi il 7 Gen 2014
Thanks a lot, choclate warrior! It works. Don't mind my previous comment. I get it now. Again. Thanks

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by