How do you change an entire row or column of an array to a certain value
151 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Shawn Blancett
il 15 Set 2017
Commentato: Star Strider
il 13 Set 2023
If I have an array of all zeros X = zeros(N) How do I change a column to a value I want.
0 Commenti
Risposta accettata
Star Strider
il 15 Set 2017
One option:
N = 5;
X = zeros(N);
X(:,3) = rand(N, 1); % Change Column #3 To A Specific Vector
X(2,:) = 5*ones(1, N); % Change Row #2 To a Row Of ‘5’
4 Commenti
Star Strider
il 13 Set 2023
@Riley Harris — Yes, however it can easily be vectorised. Using the sub2ind function is another option.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!