How to: taking out 2d matrix from 3d matrix
41 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
adi kul
am 19 Mai 2016
Kommentiert: adi kul
am 19 Mai 2016
Hello All, I need help in 3d matrix. I have z as 2x20x30 matrix which I will represnt here as:
z(i,m,n)
Now I want to take out z1 as (m,n) and z2 as (m,n) matrix from this. Meaning the i from z(i,m,n) is i=1:2. So z1 will be (m,n) when i=1 and z2 will be (m,n) when i=2
What I did is:
z1(m,n)=z(1,m,n)
z2(m,n)=z(2,m,n)
But this yields only 1 value and rest of z1 matrix values turns out as zero.
I am not sure how to pull this out. Can anyone help me? I hope you understand my problem. Regards, Adwait
0 Kommentare
Akzeptierte Antwort
Guillaume
am 19 Mai 2016
Azzi showed you one way to do it. You could also do
z1 = squeeze(z(1, :, :));
z2 = squeeze(z(2, :, :));
the permute beforehand has the advantage you don't need to squeeze out the singleton dimension.
But more importantly, there is no reason for you to split out your matrix anyway. Whenever in your later code, you use z1 you could simply use z(1, :, :) and whenever you use z2 you simply use z(2, :, :). As a rule, you shouldn't be numbering variables. If the variables are numbered it really means that their content should be put together in array, which is what you started with.
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!