Hello, I have a 3-dimensional matrix m = cat(3,rand(5), rand(5),rand(5)) - for example. How can I specify a new name m3 for m(:,:,3) to call smth like m3(:) (cause it's impossible to call m(:,:,3)(:)) - without creating new variable?

4 件のコメント

Stephen23
Stephen23 2017 年 7 月 20 日
編集済み: Stephen23 2017 年 7 月 20 日
While it is possible to do that, magically defining new variable names like that would make your code slow, buggy, hard to read, hard to debug, very inefficient,...:
Mariya Zapletina
Mariya Zapletina 2017 年 7 月 20 日
Efficiency of alternative naming for the part of matrice that I need bases on the fact, that I will not create new variable (as in your answer with :
tmp = m(:,:,3);
tmp(:)
I will save some memory not creating one more variable and only pointing to a part of existing variable.
It's interesting to me to know if there are some insrtuments for realizing this in MATLAB.
Stephen23
Stephen23 2017 年 7 月 20 日
編集済み: Stephen23 2017 年 7 月 20 日
@Mariya Zapletina: See Andrei Bobrov's comment and example.
Mariya Zapletina
Mariya Zapletina 2017 年 7 月 20 日
Thank you for attention!

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

 採用された回答

Stephen23
Stephen23 2017 年 7 月 20 日
編集済み: Stephen23 2017 年 7 月 20 日

1 投票

What is wrong with simply doing this?
tmp = m(:,:,3);
tmp(:)
or using reshape ?

2 件のコメント

Andrei Bobrov
Andrei Bobrov 2017 年 7 月 20 日
reshape(m(:,:,3),[],1)
Mariya Zapletina
Mariya Zapletina 2017 年 7 月 20 日
Thank you! It helped!

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by