Fill an array over an iteration

3 views (last 30 days)
luca
luca on 10 Sep 2019
Answered: the cyclist on 10 Sep 2019
Given the following code
D= [1 2 3 ; 4 5 6 ]
for i= 1: size(D,1)
M = [4 2 4 3 2; 2 1 3 1 2; 4 1 2 3 1];
r= size(M,1)
c=size(M,2)
Tc=cumsum(M)
T=cumsum(Tc,2)
%T= [4 6 10 13 15; 6 0 0 0 0 ; 10 0 0 0 0]
for j= 2:size(T,1)
for k= 2:size(T,2)
T(j,k)=max(T(j,k-1)+M(j,k),T(j-1,k)+M(j,k))
end
end
rowNum = find(any(T >18,2),1,'first');
B=D(i,:);
Dstop=B(1:rowNum-1)
BBB(i,:)=B(:) %% HERE THE PROBLEM
end
I have a problem in the penultime row, where I want to fill the vector BBB with the value Dstop that I obtain at each cycle
does someone may help me?

Accepted Answer

the cyclist
the cyclist on 10 Sep 2019
Does using
BBB(i,:)=Dstop
instead of
BBB(i,:)=B(:)
do what you want?
If not, you need to explain a bit more.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!