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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by