フィルターのクリア

Creating Matrix using nested for loop?

1 回表示 (過去 30 日間)
Sima
Sima 2014 年 4 月 6 日
回答済み: Lam Nguyen Van 2020 年 3 月 10 日
how would i create the following matrix using a nested for loop?
[3 6 9 12 15;
4 8 12 16 20;
7 14 21 28 35]
so far i have: m=3;
n=5;
C=zeros(m,n);
for j=1:n
for i=1:m
C(i,j) =
end
end
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 6 日
For the first column, why 3, 4 then 7 ?
Sima
Sima 2014 年 4 月 6 日
its a question that practices making certain matrices using a nested for loop and the answer has to contain a nested for loop

サインインしてコメントする。

回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 6 日
Maybe you want this
n=5;
m=6;
out=cell2mat(arrayfun(@(x) x:x:n*x,(1:m)','un',0))

Roger Stafford
Roger Stafford 2014 年 4 月 7 日
How about
C = [3;4;7]*(1:5);
or
C = zeros(3,5);
for r = [3,4,7]
for c = 1:5
C(r,c) = r*c;
end
end
  1 件のコメント
Alberto
Alberto 2014 年 4 月 7 日
m=3; n=5; C=zeros(m,n); A=[3 4 7]; for k=1:length(A) for j=1:5 C(k,j)= A(k)*j end end

サインインしてコメントする。


Lam Nguyen Van
Lam Nguyen Van 2020 年 3 月 10 日
Hi,
I want to creat matrices automatically with for loop in Matlab?
phi1=30; phi2=45; phi3=90;
After running the code I want to have a matric A with the following elements:
A=[sin(phi1) cos(phi1) sin(phi1)*cos(phi1);
sin(phi2) cos(phi2) sin(phi2)*cos(phi2);
sin(phi3) cos(phi3) sin(phi3)*cos(phi3);]
Thanks.

カテゴリ

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