combine cells with unequal dimensions

3 views (last 30 days)
Amr Hashem
Amr Hashem on 25 Jul 2015
Answered: Amr Hashem on 26 Jul 2015
i have two tables ( A 13*52 cell & B 19*75 cell )
A
& B
first column in each(A & B) has a some duplicated numbers ( 4368042 - 4324685 - 4321114 )
i want to found duplicated numbers in first columns and if exist copy all rows of it
to a new table consists of [ A , New B]
New B = only duplicated numbers ( 4368042 - 4324685 - 432111)
i write this code:
clear all; clc
tic
[ndata2 text2 alldata2] = xlsread('datecode.xlsx','devtex');
[ndata text alldata] = xlsread('datecode.xlsx','mdr');
[R1,C1]=size(alldata2);
[R2,C2]=size(alldata);
colsize=max(C1,C2);
for i=1:size(alldata,1)
for j=1:R1 %length(Defs)
if alldata2{j,1}==alldata{i,1}
data1(j,:)=alldata(i,:);
end
end
end
new_table=[alldata2,data1];
but i got an error in the last line :
CAT arguments dimensions are not consistent.
Error in ==> mdrtry at 37
new_table=[alldata2,data1];
how i can solve this ?
  8 Comments
Amr Hashem
Amr Hashem on 25 Jul 2015
Edited: Amr Hashem on 25 Jul 2015
here is the excel sheet, i worked on and the code i write is :
clear all; clc
tic
[ndata2 text2 alldata2] = xlsread('datecode.xlsx','devtex');
[ndata text alldata] = xlsread('datecode.xlsx','mdr');
[R1,C1]=size(alldata2);
[R2,C2]=size(alldata);
colsize=max(C1,C2);
querydevt=alldata2(:,1);
querymdr=alldata(:,1);
a1 = cat(1,querydevt{:});
a2 = cat(1,querymdr{:});
idx = ismember(a2,a1);
idx2 = [alldata(idx,:)]; % all def texts
idx3 = ismember(a1,a2);
idx4 = [alldata2(idx3,:)];
new_table=[idx4 idx2]
toc
i want to create a new table contain new A and new B which is new_table=[idx4 idx2]
How i can do this?
Amr Hashem
Amr Hashem on 25 Jul 2015
Edited: Amr Hashem on 25 Jul 2015
I hope a guy pass from here and provide me with an answer :)

Sign in to comment.

Answers (1)

Amr Hashem
Amr Hashem on 26 Jul 2015
this code do what I want :
clear all; clc
tic
[ndata2 text2 alldata2] = xlsread('all.xlsx','all10t14');
[ndata text alldata] = xlsread('mdr1.xlsx','1');
[R1,C1]=size(alldata2);
[R2,C2]=size(alldata);
colsize=max(C1,C2);
querydevt=alldata2(:,1);
querymdr=alldata(:,1);
a1 = cat(1,querydevt{:});
a2 = cat(1,querymdr{:});
idx = ismember(a2,a1);
data1 = [alldata(idx,:)]; % all def texts
idx3 = ismember(a1,a2);
data2 = [alldata2(idx3,:)];
[R3,C3]=size(data1); % size of data1
[R4,C4]=size(data2);
data3=cell([R3,C4]); % to rearrange the data3
for i=1:size(data1,1)
for j=1:length(data1)
if data1{j,1}==data2{i,1} % if MDR of all = MDR of event date
data3(j,:)=data2(i,:); % save data2 'all' newfile 'data3' (56 fields)
end
end
end
match=[data1,data3];
xlswrite('mdr1.xlsx',idx2,2);
toc
Thanks to you all :)

Categories

Find more on Entering Commands in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!