wrong dimensions on a 3D array

4 Ansichten (letzte 30 Tage)
cameron lord
cameron lord am 29 Nov. 2020
Kommentiert: cameron lord am 30 Nov. 2020
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 29 Nov. 2020
%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 Kommentar
cameron lord
cameron lord am 30 Nov. 2020
thanks that's great, used the permute function

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by