How to reshape/transform matrices with 3D data?

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

help meshgrid
help ndgrid
help reshape
Pleas provide a small example of inputs and outputs.
I added an example.

댓글을 달려면 로그인하십시오.

 채택된 답변

James Tursa
James Tursa 2017년 7월 6일
[y,x] = ndgrid(Y,X);
x = x(:);
y = y(:);
z = reshape(Z',[],1);

댓글 수: 3

Thank you! One more question:
When X and Y don't have the same number of elements it gives me this error:
Subscripted assignment dimension mismatch
Do you have any further idea how to fix this?
Stephen23
Stephen23 2017년 7월 7일
편집: Stephen23 2017년 7월 7일
@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.
Hi, i would like to ask how to reshape back the data from right to the left of above figure?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2017년 7월 6일

댓글:

2020년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by