Match columns containing numbers in two cell arrays.Join the cell arrays.

조회 수: 1 (최근 30일)
avantika . 2014년 9월 9일
댓글: avantika . 2014년 9월 10일
I have a cell array named data (7886x15 cell). The 15th column of this cell array contains the information of participant number ( 1, 5 , 7, 10 ...and so on). There is another cell array called participant_detail that contains (696x29 cell) in which the 2nd column contains the participant number.
I want to write a command line that matches the participant number (i.e. 15th column of data cell array with the 2nd column of participant_detail cell array). Then picks up the corresponding row of participant_detail cell array and adds it from 16th column onward in the data cell array.
Can anyone help me out.Thanks in advance.

채택된 답변

Guillaume 2014년 9월 9일
편집: Guillaume 님. 2014년 9월 9일
Assuming that a participant can always be found:
[~, pdrow] = ismember([data{:,15}], [participant_detail{:, 2}]);
data(:,16:44) = participant_detail(pdrow,:);
If not:
[found, pdrow] = ismember([data{:,15}], [participant_detail{:, 2}]);
data(found,16:44) = participant_detail(nonzeros(pdrow),:);
  댓글 수: 6

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 9월 9일
A - cell array 7886x15; B - cell array 696x29
[l,ii] = ismember([A{:,15}],[B{:,2}]);
D = cell(size(A,1),size(B,2));
D(l,:) = B(ii(l),:);
out = [A, D];
  댓글 수: 1
avantika 2014년 9월 9일
this gives the following error: Error using horzcat Dimensions of matrices being concatenated are not consistent.

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by