Is it possible to stack tables?
Show older comments
Hi everyone, I'm facing the following problem: I do several testruns. There are about 10 tests per run, which results in 10 .csv files. I read them with Matlab, do some calculations and store about 6 values per test which I write in a table, thereby creating a 6x10 table. Those values are sometimes strings and sometimes numbers. Then I change the setting and do the next test run, evaluate the files and create the next table. I end up with about 8 tables. Now I would like to somehow stack those tables in order to compare (and plot) the influence of the setting on my test results. I would like to do something like:
all_tables(1, :, :) = table1;
all_tables(2, :, : ) = table2;
etc.
and then read the values back, e.g.
val1 = all_tables(:, 2, 1) ;
Is that possible or is there any other format which is easier to handle than tables?
Thank you in advance :)
Accepted Answer
More Answers (2)
Guillaume
on 31 Aug 2016
As Stephen says, using cell arrays may be easier.
Alternatively, you could concatenate the tables into one tall table with two extra columns (original table, and row) that you'd use for filtering:
addcols = @(t, id) [t, table(repmat(id, height(t), 1), (1:height(t))', 'VariableNames', {'TableID', 'RowID'})];
all_tables = [addcols(table1, 1);
addcols(table2, 2);
addcols(table3, 2)];
To filter:
%One row, column from all original tables
%instead of all_tables(:, 2, 1):
val1 = all_tables(all_tables.RowID == 2, 1)
%One row, all columns from one table
%instead of all_tables(1, 2, :):
val2 = all_tables(alltables.TableID == 1 & alltables.RowID == 2, :)
CrazyEngineer
on 31 Aug 2016
0 votes
Categories
Find more on Data Type Identification 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!