How to reconstruct a 3D matrix from a vector?

3 visualizaciones (últimos 30 días)
Divya R
Divya R el 1 de Mayo de 2020
Comentada: Divya R el 4 de Mayo de 2020
I have a 3D matrix A1 filled with numbers. I accessed a specific element across all the sheets to filter it. I need to do this for all the elements and create a new 3D matrix A2 of the same dimensions as A1. This is the code I’ve got so far after referring to https://in.mathworks.com/matlabcentral/answers/15463-how-to-create-a-3d-matrix-using-the-2d-matrices. The problem is that now I get the same numbers on all the sheets for A2.
The code is like this
%A1 is a 5x10x7 matrix
C1=randi(1,5,10);A2=zeros(5,10,7);
for i=1:5
for j=1:10
T2 = reshape(A1(i,j,:), [],1);
k=smoothdata(T2,'movmean');
A2(i,j,:)=k(A1(i,j));
end
end

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 1 de Mayo de 2020
In the code you have written in the question. You defined, A1 to be of the wrong dimension. Try the following code to see the correct syntax to smooth data along the 3rd dimension.
A1=rand(5,10,7);A2=zeros(5,10,7);
for i=1:5
for j=1:10
T2 = reshape(A1(i,j,:), [],1);
k=smoothdata(T2,'movmean');
A2(i,j,:)=k;
end
end
In fact, smoothdata already gives the option to smooth the data in the third dimension. The above code is equivalent to these two lines
A1=rand(5,10,7);
A2 = smoothdata(A1, 3, 'movmean');

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by