How to replace a column with an incremented vector starting at -10?

1 visualizzazione (ultimi 30 giorni)
I have some time data and I am trying to replace an invalid column with data starting at -10 and increases in increments of .1 up to the length of the dataset. How would I go about this?
  2 Commenti
Jan
Jan il 17 Mag 2017
Please post some code, which creates a dataset like yours. "some time data" is not enough to guess this detail reliably. How can the "invalid" columns be identified?

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 17 Mag 2017
Modificato: Stephen23 il 17 Mag 2017
>> M = rand(12,6); % example data
>> col = 4; % specify which column
>> M(:,col) = (1:size(M,1))-11
M =
0.53477 0.48090 0.36142 -10.00000 0.83279 0.27853
0.16247 0.14570 0.25672 -9.00000 0.80810 0.03114
0.05016 0.80648 0.86410 -8.00000 0.38718 0.34066
0.66991 0.61923 0.74592 -7.00000 0.23169 0.98405
0.14010 0.76240 0.09419 -6.00000 0.23363 0.02649
0.18001 0.00460 0.03549 -5.00000 0.60986 0.28603
0.92897 0.72864 0.67928 -4.00000 0.70401 0.01101
0.24724 0.90098 0.25873 -3.00000 0.64998 0.94363
0.98211 0.64409 0.32472 -2.00000 0.37861 0.60439
0.87888 0.29503 0.64717 -1.00000 0.46550 0.89163
0.00736 0.21508 0.01827 0.00000 0.46535 0.53023
0.55577 0.28285 0.53249 1.00000 0.77927 0.53609
  3 Commenti
Guillaume
Guillaume il 17 Mag 2017
Well, it's trivial to change:
M(:, col) = startvalue + (0:size(M, 1)-1) * increment;
So:
M(:, col) = -10 + (0:size(M, 1)-1) * 0.1;

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by