Turning array values into values on an x axis

6 Ansichten (letzte 30 Tage)
Tom
Tom am 1 Mai 2012
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 Kommentare
Daniel Shub
Daniel Shub am 1 Mai 2012
You link to double seems broken.
What have you tried so far?
Matt Fig
Matt Fig am 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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Wayne King
Wayne King am 1 Mai 2012
x = ones(500,1);
indices = [2 3 6 9];
x(indices) = 2;
Or
x = ones(500,1);
x(indices) = x(indices)+1;
  3 Kommentare
Daniel Shub
Daniel Shub am 1 Mai 2012
Ummm, it is 1x4 in Wayne's answer. It works if you make it 4x1.
Tom
Tom am 2 Mai 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by