How to output a matrix (column by column) after looping

6 ビュー (過去 30 日間)
Hong Wei Tang
Hong Wei Tang 2021 年 8 月 20 日
コメント済み: Awais Saeed 2021 年 8 月 20 日
for a=1:1:3
for b=1:1:3
c=a+b;
matrix(:,:)=c;
end
end
The answer of matrix(:,:) supposes to show in variables - matrix(same sheet):
(First looping) (Second looping) (Third looping)
2 3 4
3 4 5
4 5 6
Thanks. Have a great day.

採用された回答

Awais Saeed
Awais Saeed 2021 年 8 月 20 日
clc;clear all;close all
for a=1:1:3
for b=1:1:3
c=a+b;
matrix(b,a)=c; % you must store values this way, not like matrix(:,:) = c
end
end
  2 件のコメント
Hong Wei Tang
Hong Wei Tang 2021 年 8 月 20 日
Thank you for your answer. How about c is a matrix? What should I do with the code? I am really struggling with this such a long time......
Awais Saeed
Awais Saeed 2021 年 8 月 20 日
I do not know what you are exactly trying to say. I am writing a sample code below. You can debug the code to see how it works (to see how you can place values in specific rows and columns)
c = [1 2 3; 4 5 6; 7 8 9;]; % a 3x3 matrix
for row=1:1:size(c,1)
for col=1:1:size(c,2)
matrix(row,col)=c(row,col)
end
end

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by