Combining two matrices of the same size to create a new matrix where each cell contains both values from the parent matrices.

18 ビュー (過去 30 日間)
Hello all, hope I can get a hand with this as I have hit a wall. I have two matrices, tempK and distance_map, both of which are 240x320. I want to create a new matrix which combines both into a single 240x320 matrix, with each cell containing the value from tempK and distance_map (basically each cell in the new matrix will have two values, a distance value and a temperature value).
I have tried,
C = [distance_map, tempK]
and
C = [distance_map; tempK]
but to no avail. Any help is greatly appreciated.

採用された回答

Iain
Iain 2014 年 9 月 9 日
You've got 2 options:
1. Create a 240 x 320 x 2 matrix: (or 2 x 240 x 320 or whatever)
C(:,:,1) = distance_map;
C(:,:,2) = tempK;
To see a pair of values: C(45,23,:) To get a temp: C(32,52,2)
2. Create a 240 x 320 cell array:
for i = 1:240
for j = 1:320
C{i,j} = [distance_map(i,j) tempK{i,j}];
end
end
To see a pair of values: C{45,23} To get a temp: C{32,52}(2)
Given that you have "just" numerical data, I'd avoid using a cell array if possible.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by