Writing a matlab program to create a matrice column by column?

1 回表示 (過去 30 日間)
Reelz
Reelz 2012 年 4 月 13 日
I am trying to write a matlab program to create a matrice column by column and whose entries are columnwise successive integers, how would I do this? Some light explanation would help me in the right direction toward creating other matrices.

回答 (1 件)

Geoff
Geoff 2012 年 4 月 13 日
You need to be a little clearer...
Do you mean this?
A = [ 1 2 3 4
1 2 3 4
1 2 3 4 ];
Or this?
A = [ 1 1 1 1
2 2 2 2
3 3 3 3 ];
Or this?
A = [ 1 4 7 10
2 5 8 11
3 6 9 12 ];
[edit]
Righto. Well, you already know how to generate a vector of consecutive values with the colon-operator...
A = 1:12;
It's just that it's the wrong shape.
Since you need to do some of this yourself, have a look at the MatLab command reshape.
doc reshape
And I'm sure you can figure out the rest. You just need to work out how many values to generate, given your dimensions.
  4 件のコメント
Jan
Jan 2012 年 4 月 13 日
+1: Maximum help without stealing the chance to submit a homework.
Reelz
Reelz 2012 年 4 月 17 日
function m = colmat(r,c)
% contruct row wise then transpose, then use reshape to make matrice column by column
m = zeros(r,c);
v = (1:r)';
for i = 1 : c
m(:,i) = v;
end
*How would I add reshape to the command to create an example like the third? I keep getting errors

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by