Filter löschen
Filter löschen

How to make certain elements of a matrix equal to one?

3 Ansichten (letzte 30 Tage)
James
James am 2 Okt. 2013
Kommentiert: Walter Roberson am 13 Sep. 2022
For example, if I had:
x = zeros(1,100)
and I wanted to make the 3rd, 5th, 67th, and 93rd element equal to one, how could I do this?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Okt. 2013
x([3, 5, 67, 93]) = 1;
  2 Kommentare
Moe Joe
Moe Joe am 12 Sep. 2022
But the problem in this solution the newly generated vector will be with 93 elements, so how to keep the new-x as 100 elements after the solution?
Walter Roberson
Walter Roberson am 13 Sep. 2022
No, with that code, the size of x will not change unless it had fewer than 93 elements. But the user said that x = zeros(1,100) so we know that it already exists with 100 elements.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by