adding a value until a particular value

조회 수: 2 (최근 30일)
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2017년 2월 25일
댓글: Nikolas Spiliopoulos 2017년 2월 26일
Hi,
questions never end!
I have an array 17x365 and some initial values in the first row.
So I would like to add a particular number in every column like this: example First element in each row=[1], I an external value (let's say 2).
So I would add the value 0.52 in each time step like this [1 ; 1.52; 2.04; 2.56;3;3;3;.....]
I add the value 2, in small amount of 0.52 until it is depleted and then take the final value (3) and put it in the rest of the column
I don't know if I explained it well
please help!!
thanks>>!

채택된 답변

Stephen23
Stephen23 2017년 2월 26일
>> stp = 0.52; % step
>> ini = [1,4,2,0]; % initial value
>> mxv = [3,7,4,3]; % max value
>> num = 10; % number of rows
and now generate the matrix:
>> vec = stp*(0:num-1).';
>> mat = bsxfun(@plus,ini,vec);
>> mat = bsxfun(@min,mat,mxv)
mat =
1 4 2 0
1.52 4.52 2.52 0.52
2.04 5.04 3.04 1.04
2.56 5.56 3.56 1.56
3 6.08 4 2.08
3 6.6 4 2.6
3 7 4 3
3 7 4 3
3 7 4 3
3 7 4 3

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by