Add a known column to a matrix 'n' times without a loop?
Mostra commenti meno recenti
Hi Guys!
Is there a way of qriting the script below without the loop? I'm sure there's a way but I can't find it in the help section or the internet.
I want to add a known column of numbers to a matrix 'n' times.
Thank you!
Ken
clear all
clc
a=zeros(5,6); % matrix a
[m,n]=size(a);
b=zeros(m,n); % matrix b
b(1:10)=[8 8 8 8 8 10 10 10 10 10];
for i=3:n;
b(:,i)=[1 2 3 4 5];
end
4 Commenti
Daniel Shub
il 22 Mag 2011
There are lots of ways, but why would you want to?
ken
il 22 Mag 2011
Walter Roberson
il 22 Mag 2011
These days "for loops" are not necessarily slower, and in some cases are faster.
ken
il 22 Mag 2011
Risposta accettata
Più risposte (1)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!