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

18 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Iain
Iain le 9 Sep 2014
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.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by