apply if-else-statement to a 3D matrix
Show older comments
Dear community,
Maybe this is a somewhat obvious question, but I have a 3D matrix with normally distributed simulations like the following:
n=10000
x1 = 75:125;
y1 = 0:40;
Qd=zeros(n,length(y1),length(x1));
for i = 1:length(x1) % mean
for j = 1:length(y1) % sd
Qd(:,i,j)=normrnd(x1(i),y1(j),n,1);
end
end
Based on this matrix, I want to create another one with 3 conditionals. If the element Qd(k,i,j) is less than 25 then the new matrix should have a 50; if it is between 25 and 50 it should give me 10; if it is greater than 50 it should give me 30. The problem is that I have tried with the following and the elseif command is not working properly :( Any hint will be really appreciated! Thank you!
Pw=zeros(n,length(y1),length(x1));
for k = 1:n
for i = 1:length(x1)
for j = 1:length(y1)
if Q_d(k,i,j)<=25
Pw(k,i,j)=50;
elseif 25<Q_d(k,i,j)<=50
Pw(k,i,j)=10;
else
Pw(k,i,j)=30;
end
end
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics 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!