1

I have the following problem in MATLAB.

 f1  [4757*256] table
 f2  [4757*512] table
 f3  [14073*1024] table

While I can easily join f1 and f2 with

 f1n = join(f1,f2,'Keys','RowNames');

I cannot do the same with f1 , f3 in

 f3n = join(f1,f3,'Keys','RowNames');

and I recieve the following error:

Both tables must have the same row names when using
them as the key.
Error in fuse_LL_GenreTag_features (line 33)
F3new  = join(f1,f3,'Keys','RowNames');

f3 has got most row names as f1 but NOT necessarily all. Indeed what it is ideal to do is to keep the rows that are common in both tables. How can this be done in your opinion?

Thanks for your feedbacks

EBH
  • 10,350
  • 3
  • 34
  • 59
yas yasi
  • 215
  • 1
  • 6
  • 16

1 Answers1

0

As long as the first table row names is a subset of the second, you will get a new table with the common rows.

From MATLAB docs:

If you specify the value 'RowNames', then join uses the row names of A and row names of B as keys. In this case, there must be a row in B for every row in A.

Consider these tables:

f1 = array2table(zeros(3,4),'RowNames',{'a','b','c'});
f2 = array2table(zeros(3,5),'RowNames',{'a','d','c'});
f3 = array2table(zeros(5,5),'RowNames',{'a','e','c','d','b'});

the following joins will work, because the first table is a subset of the second:

f1n = join(f1,f3,'Keys','RowNames');
f2n = join(f2,f3,'Keys','RowNames'); 

however this will not work:

f1n = join(f3,f1,'Keys','RowNames');
f2n = join(f3,f2,'Keys','RowNames');

and will return an error: "Both tables must have the same row names when using them as the key".

So, in your case I believe that flipping the order of the table should work:

f3n = join(f3,f1,'Keys','RowNames');
EBH
  • 10,350
  • 3
  • 34
  • 59