how to define row matrix in which first few elements are non zero rest are zeros in matlab
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Satishkumar D
am 3 Sep. 2015
Beantwortet: Star Strider
am 4 Sep. 2015
i want to define row matrix, length of row matrix = 209; in this row matrix elements for these positions : 0, 3, 7, 13, 21 are 1 and rest are zeros;
one way is straight forward.. just typing row matrix.
any shortcuts to write row matrix in matlab?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 4 Sep. 2015
This works:
v = zeros(1,209);
v([1, 3, 7, 13, 21]) = 1;
MATLAB indexing begins with 1, not 0, so I changed your index vector to conform to that. You may have to change your other index elements (perhaps add 1 to each of them), but that will not affect the code.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!