Two basic questions in matlab

Hello all, I used matlab for some time, but this did not made me thorough with basics.
1. If I have two matrices, I1 3x3 and I2 4x4. How I can concatenate them? Is it possible? If I do [I1,I2] it will not work as both have different dimensions.
2. If I have array of 100 random numbers and I want every 4th element starting from 20th location till end, can I do this? I want to do this without any loops.
Any ideas very welcome! Thanks in advance!!

1 件のコメント

Adam
Adam 2014 年 11 月 5 日
What would you expect to be the result of concatenating a 3*3 matrix with a 4*4 matrix?

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

回答 (1 件)

Matt Tearle
Matt Tearle 2014 年 11 月 5 日
編集済み: Matt Tearle 2014 年 11 月 5 日

1 投票

1. It won't let you. Two options: (a) pad with something, such as NaNs, (b) use cell arrays to store each matrix in a separate cell. For (a):
X = [[l1;NaN(1,3)] l2]
2. Use the range (:) operator with a step:
y = x(20:3:end)
(Assuming "every 4th element starting from 20th" you mean 20, 23, 26, etc)

3 件のコメント

Image Analyst
Image Analyst 2014 年 11 月 5 日
Wouldn't it be
y = x(20:4:end);
to give 20, 24, 28, 32, etc.?
Matt Tearle
Matt Tearle 2014 年 11 月 5 日
I initially had that, but then somehow decided that "every 4th element" would mean like a musical interval 4th (thinking of blocks of 4 elements, including the last one). But now that I think about it again, I'm back with you -- x(20:4:end) would make more sense.
I guess Amit can figure out his interpretation and choose accordingly :)
Amit Kumar
Amit Kumar 2014 年 11 月 6 日
Yup, I can figure out :) Thanks a lot Matt, Image Analyst!

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

質問済み:

2014 年 11 月 5 日

コメント済み:

2014 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by