How can we store many matrices(z) from for loop in a single matrix D(say) in my problem.

1 回表示 (過去 30 日間)
MOHD UWAIS
MOHD UWAIS 2020 年 5 月 15 日
回答済み: Prasad Reddy 2020 年 5 月 17 日
x=[1 2 3];
y=1./x;
for l=1:3;
I=eye(3,3);
z=y(l)*I;
end

回答 (1 件)

Prasad Reddy
Prasad Reddy 2020 年 5 月 17 日
% If you want your matrices z1,z2,z3 to be stored in side by side ie D=[z1 z2 z3] the following code helps
clc
clear all
x=[1 2 3];
y=1./x;
D=[];
for l=1:3;
I=eye(3,3);
z=y(l)*I;
D=[D,z]
end
% If you want your matrices z1,z2,z3 to be stored in a column manner ie D=[z1
% z2
% z3]
%the following code helps
clc
clear all
x=[1 2 3];
y=1./x;
D=[];
for l=1:3;
I=eye(3,3);
z=y(l)*I;
D=[D;z]
end
% Please give a up thumb if this answer works for you. Thank you.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by