How to make a 2d structure from 3d structure??

1 Ansicht (letzte 30 Tage)
Ashish Mishra
Ashish Mishra am 16 Apr. 2020
Kommentiert: Tommy am 17 Apr. 2020
I have a structure(Say A) of size 20 × 18 × 4.
I want to convert it to(Say B) of size 80 × 18
I tried with
B = reshape(A,80,18)
Is this correct?? Please suggest
  2 Kommentare
Mehmed Saad
Mehmed Saad am 16 Apr. 2020
Bearbeitet: Mehmed Saad am 16 Apr. 2020
Yup it is correct for arrays and cells
Example
x = rand(20,18,4);
y = reshape(x,80,18);
Ashish Mishra
Ashish Mishra am 16 Apr. 2020
Bearbeitet: Ashish Mishra am 16 Apr. 2020
@Muhammad Saad, No, I checked it. The column 2 (val(: , : , 1)) is coming in coulumn 1 from row 21 to row 40. I want to keep my columns intact while concatenating 20× 18 structures four times.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Mehmed Saad
Mehmed Saad am 16 Apr. 2020
x(1,1,1) = 1;
x(1,1,2) = 2;
x(1,2,1) = 3;
x(1,2,2) = 4;
x(2,1,1) = 5;
x(2,1,2) = 6;
x(2,2,1) = 7;
x(2,2,2) = 8;
Now type
x(:)
Output will be
ans =
1
5
3
7
2
6
4
8
When you feed data to reshape it converts into this and then reshape to your given dimensions forexample
reshape(x,2,4)
ans =
1 3 2 4
5 7 6 8
Inorder to change which data to pick you have to premute the dimensions for example
x = permute(x,[3 2 1]);
x(:)
ans =
1
2
3
4
5
6
7
8
Hope this helps
  1 Kommentar
Tommy
Tommy am 17 Apr. 2020
Ashish,
For your example, I believe this would be
B = reshape(permute(A,[1 3 2]),80,18);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by