Fill an array over an iteration

3 Ansichten (letzte 30 Tage)
luca
luca am 10 Sep. 2019
Beantwortet: the cyclist am 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?

Akzeptierte Antwort

the cyclist
the cyclist am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by