# Processing 2D into 3D matrix

1 visualizzazione (ultimi 30 giorni)
Minas Emiris il 1 Apr 2020
Commentato: Minas Emiris il 1 Apr 2020
Hi all.
I have a matrix (phi), say of 1502 rows (harmonic) by 10 columns (observations), where the i,j th element represents the phase of the ith harmonic of the jth observation; say the name of the matrix is X;
I need to find the modeshape corresponding to each harmonic; say y = sin(x + phi(i,j)), where x is a position vector, say x = 0:1:11 (11 position elements);
But since each of these modeshapes has its own corresponding 11 'y' values, what I need is a 3D matrix with size 1502x10x11 with all the modeshape values. How can I use the 2D matrix phi to get the 3D matrix (Modeshapes) that I want?
I tried the following code, which gives a better indication of what I need but it didn't work.
modeshapes = zeros(1502,10,11)
x = 0:1:11
for i = 1:1502
for j = 1:10
modeshapes(i,j,:) = sin(phi(i,j)+x)
end
end
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Andrei Bobrov il 1 Apr 2020
modeshapes = sin(phi + reshape(x,1,1,[]));
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Minas Emiris il 1 Apr 2020
Thank you very much, this works.

Accedi per commentare.

### Più risposte (1)

J Chen il 1 Apr 2020
You need to change the following statement
x = 0:1:11
x has 12 elements but the modeshapes array only allows 11 elements in the third dimension.
##### 2 CommentiMostra NessunoNascondi Nessuno
J Chen il 1 Apr 2020
BTW, it's a good practice to add a semicolon (;) at the end of each statement to supress its output.
Minas Emiris il 1 Apr 2020
Pardon, it's x = 0:1:10; but it's not because of what you're saying.

Accedi per commentare.

### Categorie

Scopri di più su Programming in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by