How to reshape/transform matrices with 3D data?

1 vue (au cours des 30 derniers jours)
Manuela Gräfe
Manuela Gräfe le 6 Juil 2017
Commenté : hanif hamden le 16 Nov 2020

Hello!

I would like to reshape/transform matrices with 3D data (see attached photo). Is there an existing method for this?

Thank you

- - - - - - - - - - - - - - -

Edit:

Initial situation:

X=[1;2;3];
Y=[1,2,3];
Z=[1,2,3;4,5,6;7,8,9];

Target:

X=[1;1;1;2;2;2;3;3;3];
Y=[1;2;3;1;2;3;1;2;3];
Z=[1;2;3;4;5;6;7;8;9];
  3 commentaires
James Tursa
James Tursa le 6 Juil 2017
Pleas provide a small example of inputs and outputs.
Manuela Gräfe
Manuela Gräfe le 6 Juil 2017
I added an example.

Connectez-vous pour commenter.

Réponse acceptée

James Tursa
James Tursa le 6 Juil 2017
[y,x] = ndgrid(Y,X);
x = x(:);
y = y(:);
z = reshape(Z',[],1);
  3 commentaires
Stephen23
Stephen23 le 7 Juil 2017
Modifié(e) : Stephen23 le 7 Juil 2017
@Manuela Gräfe: ndgrid does not require its inputs to have the same number of elements:
>> [Xm,Ym] = ndgrid(1:2,1:9); % no error!
>>
So you have an error but you did not show us the complete error message and you did not show us the code... If you actually want help then you should show us what you tried and the complete error message. Thia means all of the red text.
hanif hamden
hanif hamden le 16 Nov 2020
Hi, i would like to ask how to reshape back the data from right to the left of above figure?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by