How to merge similar matrixes and list them on columns.

1 Ansicht (letzte 30 Tage)
Robert
Robert am 9 Sep. 2013
Hi Matlab users,
OK, so I have a 238x132 matrix representing current movements in one day(let's call it U), and two 238x132 matrixes representing one Latitude and one Longitude (they are like this because they are gridded). What I need to do is to put all three of them on columns like this: Latitude Longitude U where Latitude and Longitude have the same positions inside their matrixes as U.
I can do it like this: U11=[Latitude(1,1) Longitude(1,1) U1(1,1)]; but it takes a lot of time. Is there a easier way?
I am really ashamed for not knowing this.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 9 Sep. 2013
Bearbeitet: Andrei Bobrov am 9 Sep. 2013
Umn = [Latitude(:) Longitude(:) U(:)];
other variant
M = cat(3,Latitude,Longitude,U);
C = cellfun(@(x)x(:)',num2cell(M,3),'un',0);
out = cell2mat(C);
more variant
M = cat(3,Latitude,Longitude,U);
out = reshape(permute(M,[3 2 1]),[],size(U,1))';
or
M = [Latitude(:),Longitude(:),U(:)];
out = reshape(permute(reshape(M',3,size(U,1),[]),[2 1 3]),size(U,1),[]);

Weitere Antworten (0)

Kategorien

Mehr zu Descriptive Statistics 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!

Translated by