How to reconstruct a 3D matrix from a vector?

5 vues (au cours des 30 derniers jours)
Divya R
Divya R le 1 Mai 2020
Commenté : Divya R le 4 Mai 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

Réponse acceptée

Ameer Hamza
Ameer Hamza le 1 Mai 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');
  1 commentaire
Divya R
Divya R le 4 Mai 2020
This worked. Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by