Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

How to include a second loop in my script

1 view (last 30 days)
Konstantina Vaitsi
Konstantina Vaitsi on 14 May 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
I have created the following script and it works ok. However, I need to somehow include a second loop so that every Y matrix is calculated upon the previous one and not on the initial CLN matrix. For example, the first step gives Y = 56 for the first cell, so I want the second step to calculate Y = 56+0.5*B(i,j) and so on. Any suggestions? Thank you :)
S = [12 4 6 4;16 12 2 3;0 4 10 12;4 12 21 3];
CLN = 50*ones(4);
for t = 0:4
B = [S - 2*t];
B(B<0)=0
Y = zeros(size(B));
for i = 1:4
for j = 1:4
if (B(i,j)<5);
Y = CLN(i,j) - 0.5*B(i,j)
elseif(CLN(i,j)-0.5*B(i,j)<0)
Y = 0
else(B(i,j)>=5);
Y = CLN(i,j) + 0.5*B(i,j)
end
end
end
end
  1 Comment
Rik
Rik on 14 May 2020
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!