Matlab: join two cell arrays or structures

How is it possible in Matlab to join two cell arrays or structures?

I've a first cell array (or structure):

Name
A1
A1
B1
C2
C2

a second cell array (or structure):

Name  Value Type
A1     1     a
B1     56    b
C1     12    c
C2     58    c
C3     45    c
C4     15    c

I need to get this result:

Name  Value  Type
A1     1      a
A1     1      a
B1     56     b
C2     58     c
C2     58     c

Thanks

Answers


If the data are cell arrays: use the second output of ismember:

cell1 = {'A1';'A1';'B1';'C2';'C2'}; % example data
cell2 = {'A1',1;'B1',56;'C1',12;'C2',58;'C3',45;'C4',15}; % example data

[ii jj] = ismember(cell1,cell2(:,1));
result = cell2(jj(ii),:)

If the data are structure matrices: you only need small modifications to the code above:

mat1.Name = ['A1';'A1';'B1';'C2';'C2']; % example data
mat2.Name = ['A1';'B1';'C1';'C2';'C3';'C4']; % example data
mat2.Value = [1; 56;  12; 58;  45; 15]; % example data
mat2.Type = ['a';'b';'c';'c';'c';'c']; % example data

[ii jj] = ismember(mat1.Name,mat2.Name,'rows');
result.Name = deal(mat2.Name(jj(ii),:));
result.Value = deal(mat2.Value(jj(ii),:));
result.Type = deal(mat2.Type(jj(ii),:));

Need Your Help

Is there a way to execute android commands outside the ../sdk/tools folder?

android sdk command-prompt

When I try to execute android commands on the command line (Windows) outside the tools folder, it doesnt recognize android commands. Is there a way to fix this?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.