How can I store the values in a matrix while using for loop?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, I am a bit confused, how to store the values in a matrix while using for loop. Here is the my code
k=1.5:0.1:3;
ws=zeros(1,length(k));
dof=zeros(1,length(k));
for i=1.5:0.1:3
ws=22+4+7+i;
dof(i)=2+ ws;
end
I want to store the values pf 'ws' and 'dof' in matrix. Thanks
0 Commenti
Risposte (2)
Andrei Bobrov
il 12 Lug 2017
Modificato: Andrei Bobrov
il 12 Lug 2017
k=1.5:0.1:3;
n = numel(k);
ws=zeros(1,n);
dof=zeros(1,n);
for ii=1:n
ws(ii)=22+4+7+k(ii);
dof(ii)=2+ ws(ii);
end
or just
ws = 33 + k;
dof = ws + 2;
0 Commenti
alice
il 12 Lug 2017
You have to give the position where you want to write, like this:
k = 1.5:0.1:3;
ws = zeros(1,length(k));
dof = zeros(1,length(k));
for cpt = 1:length(k)
ws(cpt) = 22+4+7+k(cpt);
dof(cpt)= 2+ws(cpt);
end
But you don't need a loop to do this and it would be better to do simply:
k = 1.5:0.1:3;
ws = 22+4+7+k;
dof = 2+ws;
0 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!