필터 지우기
필터 지우기

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