adding a value until a particular value

2 vues (au cours des 30 derniers jours)
Nikolas Spiliopoulos
Nikolas Spiliopoulos le 25 Fév 2017
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>>!

Réponse acceptée

Stephen23
Stephen23 le 26 Fév 2017
>> 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

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by