adding a value until a particular value
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Nikolas Spiliopoulos
il 25 Feb 2017
Commentato: Nikolas Spiliopoulos
il 26 Feb 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>>!
0 Commenti
Risposta accettata
Stephen23
il 26 Feb 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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Multidimensional Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!