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

18 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Iain
Iain il 9 Set 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.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by