Add value in vector and use it as input for the next row
1 回表示 (過去 30 日間)
古いコメントを表示
Hello!
I have a column vector S(M,1) containing "0" and "1". And i have another column vector E(M,1) containing values.
I want to use a condition :
if S(i,:)==1
E1(i,:)==E(i,:)+k %k is a fixed value
but this condition is used for the first "1" in S, because in the next "1" exisiting in S i will use this condition :
if S(i,:)==1
E2(i,:)=E(i,:)+E1 ;
it means that each time i will use the previous result.
for example
S=[1 1 1 0 1 0 ], E=[4 2 5 10 2 3]; k= 10
E_result=[14 16 21 0 23 0];
I'm asking if there is a way to do that?
thanks in advance.
0 件のコメント
採用された回答
Stephen23
2022 年 10 月 17 日
S = [1,1,1,0,1,0];
E = [4,2,5,10,2,3];
k = 10;
X = S==1;
Z = S;
Z(X) = k+cumsum(E(X))
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!