Turning array values into values on an x axis

1 visualizzazione (ultimi 30 giorni)
Suppose I had a double array and the values were 2,3,6 and 9.
How would I create a double array where all of the values are 1, except the 2nd, 3rd, 6th and 9th, which are 2?
  2 Commenti
Matt Fig
Matt Fig il 2 Nov 2012
Tom's question
Suppose I had a double array and the values were 2,3,6 and 9.
How would I create a double array where all of the values are 1, except the 2nd, 3rd, 6th and 9th, which are 2?

Accedi per commentare.

Risposta accettata

Wayne King
Wayne King il 1 Mag 2012
x = ones(500,1);
indices = [2 3 6 9];
x(indices) = 2;
Or
x = ones(500,1);
x(indices) = x(indices)+1;
  3 Commenti
Tom
Tom il 2 Mag 2012
Thanks - I got there in the end - I had to round my indices for some reason. Even though some of them had .0000 after it still wouldn't work until those had been removed.
Many thanks Wayne and Daniel.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Types in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by