3d to 2d matrix

5 ビュー (過去 30 日間)
Alexandros Polykarpou
Alexandros Polykarpou 2012 年 10 月 15 日
Hi guys,
I have an [r c w] matrix where r & c are the pixels of a hyperspectral picture and the w are the number of layers of the picture.
I want to turn this matrix to [w , x] matrix.
For example. I want the values of w for the pixel 1,1 below 1. and the values of w of the pixel 1,2 below 2 until the whole table is finished.
I thought of the following commands but I'm not sure if it works because my matrix is massive.
[r,c,w]=size(reflectances) A=reshape(reflectances,w,r*c);
Thank you.

回答 (4 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 15 日
編集済み: Azzi Abdelmalek 2012 年 10 月 15 日
[r,c,w]=size(reflectances)
A=reshape(reflectances(:),r*c,[])'
  2 件のコメント
Björn
Björn 2012 年 10 月 15 日
In order to make this work, you should change the first line into:
[r,c,w]=size(reflectances)
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 15 日
Thanks Björn, when I changed my code, I missed it

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


Björn
Björn 2012 年 10 月 15 日
編集済み: Björn 2012 年 10 月 15 日
This might do the trick:
A=reshape(reflectances,1,r*c,w);
A=reshape(A,r*c,w)';
You first convert it to a [1,r*c,w] matrix. After this you convert it to a [r*c,w] matrix and taking the transpose resulting in an [w,r*c] array with the values you wanted.

Andrei Bobrov
Andrei Bobrov 2012 年 10 月 15 日
A = reshape(reflectances.',[],w).';
  1 件のコメント
Björn
Björn 2012 年 10 月 15 日
Taking the transpose of an array with more than 2 dimensions does not work

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


Alexandros Polykarpou
Alexandros Polykarpou 2012 年 10 月 15 日
IS there anyway to check if the final form of the matrix is what I want. The matrix is quite big... so any ideas? ans =
192000 356
  1 件のコメント
Björn
Björn 2012 年 10 月 15 日
編集済み: Björn 2012 年 10 月 15 日
Just check a small portion of the initial matrix and the final matrix:
reflectances(1:5,1:5,1:5)
A(1:25,1:5)
Compare these answers with each other. You can also try to check it with a dummy-matrix. Create a small matrix with random values, and then check the final answer. I did that with this code:
test_matrix=randn(4,5,3)
Then apply the method you want to try (replace 'reflectances' in the code by 'test_matrix')
And then you can easily check if the first values of each third dimension coincides with the values of the first column, and so on.
NOTE: I also fixed a typo in my first answer

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

カテゴリ

Help Center および File ExchangeHyperspectral Image Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by