Vector with if condition
Show older comments
Hi everyone,
I got stuck while trying to create a nx1 vector from a nxm matrix.
The matrix is created by two inputs, T01(n,1) and RH(1,m). The result is Td(n,m).
When an element of each row is bigger than an other parameter (Ts2), I have to pick up the value of RH.
I created this code, but it isn't working. (I'm writing here the entire code and I know it's a little bit long)
It returns a vector with all hundrends or zeros .
Could anyone help me please ?
Thank you !
function [c] = cond_humidity1 (T01, RH, c2)
n=length(T01); %size of the martixes
m=length(RH);
rho=zeros(n,1); % Allocation of some vectors
Ps2=zeros(n,1);
Ts2=zeros(n,1);
Pv_sat=zeros(n,1);
Pv=zeros(n,m);
Pv2=zeros(n,m);
Td=zeros(n,m);
T_wall=zeros(n,1); %This is the vector who's values has to be compared with Td(i,j) values
for i=1:n
rho(i) = 28.96/(0.0821*(T01(i) +273.16));
Ps2(i) = 101300 - ((c2^2)/2)*rho(i);
Ts2(i) = T01(i)-(c2^2)/2060;
T_wall(i) = Ts2(i) + 0.8*(T01(i)-Ts2(i));
Pv_sat(i) = 6.1 *10^((7.4*T01(i))/(T01(i)+240.73));
for j=1:m
Pv(i,j) = Pv_sat(i) *(RH(j)/100);
Pv2(i,j) = (Ps2(i)/101300)*Pv(i,j);
Td(i,j) = 230.73/((7.4/log10(Pv2(i,j)/6.1))-1); %Till here everything works well
if Td(i,j)>=T_wall(i) % and I checked that there exists values
c(i)=RH(j); % Td(i,j) higher than T_wall
end
end
end
end
It returns a vector with all values 100 or 0
4 Comments
Geoff Hayes
on 27 Mar 2020
Klaudio - can you provide a set of inputs to the above function that generates the problem that you are observing?
Klaudio Myrtaj
on 27 Mar 2020
Edited: Klaudio Myrtaj
on 27 Mar 2020
darova
on 27 Mar 2020
I tried this case
n = 10;
m = 15;
T01 = -rand(1,n)*350;
RH = rand(1,m);
c2 = 1;
and get
c'
ans =
Columns 1 through 5
0 0 -202.1897 -164.6581 -230.7300
Columns 6 through 10
-230.7300 -214.6403 0 0 0
Klaudio Myrtaj
on 27 Mar 2020
Edited: Klaudio Myrtaj
on 27 Mar 2020
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!