matrix columns and rows manipulating with loop

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)];

 채택된 답변

Guillaume
Guillaume 2015년 6월 5일

0 개 추천

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)]

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 6월 5일

답변:

2015년 6월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by