How to combine two tables with same variable name without change anything in the table

2 visualizzazioni (ultimi 30 giorni)
I have performed a lot of experiments and got over 50 xlsx files with over 10 arrays data in it, and each of them has the same variable names and datas, such as:
1. Experiment 1: made at 2018, the injection rate is 0.146ml/min
The content in the xlsx flie which was recored is:
Slice Time X Y
2018-bz-10-0.146-001.png 0.1 123.10 155.84
2018-bz-10-0.146-002.png 0.3 115.28 155.443
2018-bz-10-0.146-003.png 0.6 116.36 155.406
2. Experiment 2: made at 2018, the injection rate is 2.128ml/min
The content in the xlsx flie which was recored is:
Slice Time X Y
2018-bz-10-2.128-001.png 18.5 11.68 128.08
2018-bz-10-2.128-002.png 36.4 130.89 155.4
P.S. The second file just have two slices as the camera for the image slices stops earlier.
I use 'readtable' to import these xlsx files. As there are too much of them, I decide to combine all of the xlsx into one parallel table, and save it as one xlsx. Just like
Slice Time X Y Slice Time X Y
2018-bz-10-2.128-001.png 18.5 11.68 128.08 2018-bz-10-0.146-001.png 0.1 123.10 155.84
2018-bz-10-2.128-002.png 36.4 130.89 155.4 2018-bz-10-0.146-002.png 0.3 115.28 155.443
2018-bz-10-2.128-003.png 45.4 NaN NaN
Therefore, depend on this single xlsx, I can efficiently organize my datasets and copy these data to other places, while any of the data in it could be traced to its original source. Furthermore, I could modify the .m to particularly extract two arrays in all xlsx into one xlsx for further comparisons.
So could any help me about this? It seems just a simple combination of data, but matlab told me
Cannot find a common table variable to use as a key variable.
Or:
Duplicate variable name: 'Slice'.
So any solutions? Thanks!
  3 Commenti
Sandy Woo
Sandy Woo il 14 Mar 2019
Hi Peter
Thank you very much for your reply! The situation is that I have performed over 50 sets of experiments, and record the parameters of each of them, which were stored in different xlsx files. Now I wish to combine them together into one xlsx file, e.g. the 1.xlsx and 2.xlsx into 3.xlsx. So how could I do that in matlab?
I try to combine the two tables side-by-side so that I could plot them as the format of 'xyxy'. In my experiments, I cannot ensure the measurement time for each set of experiments is equivalent. Some experiments just started earlier. So the xlsx files have different numbers of rows. I wrote the code like:
A = readtable('C:\Users\s\Desktop\1.xlsx');
B = readtable('C:\Users\s\Desktop\2.xlsx');
C = cat(2,A(:,2),A(:,3),B(:,2),B(:,3));
But matlab warns like:
Error using tabular/cat (line 14)
All tables in the bracketed expression must have the same number of rows.
So how could I achieve a matrix of table like 3.xlsx? Thanks a lot for this!
Peter Perkins
Peter Perkins il 14 Mar 2019
This question doesn't make sense to me. Here are your two tables:
>> A = readtable('1.xlsx')
A =
3×4 table
Slice Time X Y
____________________________ ____ ______ ______
{'2018-bz-10-0.146-001.png'} 0.1 123.1 155.84
{'2018-bz-10-0.146-002.png'} 0.3 115.28 155.44
{'2018-bz-10-0.146-003.png'} 0.6 116.36 155.41
>> B = readtable('2.xlsx')
B =
2×4 table
Slice Time X Y
____________________________ ____ ______ ______
{'2018-bz-10-2.128-001.png'} 18.5 11.68 128.08
{'2018-bz-10-2.128-002.png'} 36.4 130.89 155.4
They have no values in common on which to join them, nor do they have the same number of rows. I don't see any way to sensibly put them side-by-side.
If you want something otyher than
>> [A; B]
ans =
5×4 table
Slice Time X Y
____________________________ ____ ______ ______
{'2018-bz-10-0.146-001.png'} 0.1 123.1 155.84
{'2018-bz-10-0.146-002.png'} 0.3 115.28 155.44
{'2018-bz-10-0.146-003.png'} 0.6 116.36 155.41
{'2018-bz-10-2.128-001.png'} 18.5 11.68 128.08
{'2018-bz-10-2.128-002.png'} 36.4 130.89 155.4
you will need to explain much more clearly.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by