Effacer les filtres
Effacer les filtres

matrix columns and rows manipulating with loop

1 vue (au cours des 30 derniers jours)
sermet
sermet le 5 Juin 2015
n=6; %which is variable, the number of vector's dimension.
i=1:(n-3);
u=cos(i-3);
u=u(:);
jn=(2*cos(u(i)));
% I need to create below arrays with loop w.r.t. the "n" and "jn";
column_1=[0;0;0;jn(1);0;0]; %number of columns is equal (n-3)
column_2=[0;0;0;0;jn(2);0];
column_3=[0;0;0;0;0;jn(3)];

Réponse acceptée

Guillaume
Guillaume le 5 Juin 2015
No need for loop. You're also better off keeping your 3 columns as one matrix rather than making individually numbered variables.
m = [zeros(n-3, 3); diag(jn)]

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by