wrong dimensions on a 3D array

4 ビュー (過去 30 日間)
cameron lord
cameron lord 2020 年 11 月 29 日
コメント済み: cameron lord 2020 年 11 月 30 日
Hi, I am new to MATLAB
I have been given a file with 72 images that are 51*51 that opens in matlab as a 72*51*51 3D matrix, however I can't seem to index out the individual images.
I would like to be able to isolate each of the images so I can multiply them element wise with another 51*51 filter matrix I made but the way I am doing it gives me an image that is the wrong size to multiply.
thanks

採用された回答

Walter Roberson
Walter Roberson 2020 年 11 月 29 日
%the below needs R2020b or later
re_arranged = permute(Matrix, [2 3 1]);
filtered = pagetimes(re_arranged, filter_matrix);
The result will be 51 x 51 x 72.
For earlier releases, there is a File Exchange contribution to do page-wise multiplication. Or you can loop:
re_arranged = permute(Matrix, [2 3 1]);
filtered = zeros(size(re_arranged));
for P = 1 : size(re_arranged,3)
filtered(:,:,P) = pagetimes(re_arranged(:,:,P), filter_matrix);
end
The permute is not strictly necessary. You could skip it and use
filtered = zeros(size(Matrix));
n = size(Matrix,2);
for P = 1 : size(Matrix,1)
filtered(P, :, :) = reshape( reshape(Matrix(P,:,:), [n, n]) * filter_matrix, [1, n, n]);
end
The output would be 72 x 51 x 51
  1 件のコメント
cameron lord
cameron lord 2020 年 11 月 30 日
thanks that's great, used the permute function

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by