Filter löschen
Filter löschen

Replacing numbers in a matrix

1 Ansicht (letzte 30 Tage)
Maruf Hoque
Maruf Hoque am 16 Jan. 2017
Kommentiert: Maruf Hoque am 16 Jan. 2017
I'm fairly new to matlab. I have a matrix that is 1000 rows and 1 column of 0's. I want to replace the 400th and 900th 0's with numbers of my choosing. These numbers will change every time I run the script (in this case I want the numbers to be 0.3 and 0.9) but they will always be the 400th and 900th numbers. What would be the best way to do this?
If this can work, I plan on doing the same with a larger sized matrix (2,000,000 rows)
  1 Kommentar
Image Analyst
Image Analyst am 16 Jan. 2017
Since you're new, here's a comment on the two answers below. Stephen's is the simplest and most direct answer for your case of a column vector of ALL zeros. Mohammad's, while slightly more complicated, is the most general and will work in the case where you have some elements that are not zeros. Either approach will work for 2 million rows.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephen23
Stephen23 am 16 Jan. 2017
Bearbeitet: Stephen23 am 16 Jan. 2017
MyArray(400) = 0.3;
MyArray(900) = 0.9;
  1 Kommentar
Maruf Hoque
Maruf Hoque am 16 Jan. 2017
if I have a list of 20 numbers that will change everyday but the location (400 or 900) will stay the same, is there a way of quickly entering everything in?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by