Command Line statements for a matrix

I'm having trouble setting up this code.
My goal is to set up a 3x3 Matrix A. Then write command line statements to perform the following operations.
a) Interchange columns 2 and 3
b) add a fourth column of zeros
c) insert a row of 1's as the new second row. ( move current 2nd and 3rd rows down)
d) remove the second column
Any help would be greatly appreciated, Thanks

3 件のコメント

per isakson
per isakson 2014 年 3 月 20 日
Isn't this your homework?
Joseph
Joseph 2014 年 3 月 20 日
It is hw But we are allowed to use the Matlab Forum for help as long as it is cited.
Joseph
Joseph 2014 年 3 月 20 日
I have b) and d) completed. the other 2 are giving me problems. thanks

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

 採用された回答

per isakson
per isakson 2014 年 3 月 20 日
編集済み: per isakson 2014 年 3 月 20 日

0 投票

Ok, here is one way of doing a)
>> m = magic( 3 )
m =
8 1 6
3 5 7
4 9 2
>> m( :, [1,3,2] )
ans =
8 6 1
3 7 5
4 2 9
>>
Why don't you try to do it with the function, cat( 2, m(:,1), ... )
.
Continue:
Does "command line statements" say that each task shall be done with one function call? If two are allowed
>> m1 = m( [1,1,2,3], : )
m1 =
8 1 6
8 1 6
3 5 7
4 9 2
>> m1(2,:) = 1
m1 =
8 1 6
1 1 1
3 5 7
4 9 2
otherwise
>> cat( 1, m(1,:), ones(size(m(1,:))), m([2,3],:) )
ans =
8 1 6
1 1 1
3 5 7
4 9 2

1 件のコメント

Joseph
Joseph 2014 年 3 月 20 日
That helps a lot. Now for c), I have no problem replacing a row with 1's, but inserting and moving other rows down is giving me peroblems

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2014 年 3 月 20 日

編集済み:

2014 年 3 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by