How to merge similar matrixes and list them on columns.

1 回表示 (過去 30 日間)
Robert
Robert 2013 年 9 月 9 日
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.

採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 9 月 9 日
編集済み: Andrei Bobrov 2013 年 9 月 9 日
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),[]);
  1 件のコメント
Robert
Robert 2013 年 9 月 9 日
Thank you, it works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by