Matrix in an equation

2 次查看(过去 30 天)
Konstantina Vaitsi
Konstantina Vaitsi 2020-5-12
I have written this script and it works ok because all the cells in CLN0 are 50. But what if each cell was different? How could I write that?
The equation is CLN(B(i,j)<5) = CLN0(i,j) - 0.5*B(i,j)
Also how do I include the CLN matrixes in the loop so that every new CLN matrix is calculated upon the previous one?
S = [12 4 6 4;16 12 2 3;0 4 10 12;4 12 21 3]
CLN0 = 50*ones(4)
i = 1:4;
j = 1:4;
for t = 0:4
B = [S(i,j)- 2*t];
B(B<0)=0
CLN = zeros(size(B));
CLN(B(i,j)<5) = 50 - 0.5*B(i,j)(B(i,j)<5);
CLN(B(i,j)>=5) = 50 + 0.5*B(i,j)(B(i,j)>=5);
CLN(50 - 0.5*B(i,j)<0) = 0(50 - 0.5*B(i,j)<0)
endfor

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by