adding a value until a particular value

2 次查看(过去 30 天)
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