Clear Filters
Clear Filters

All tables in the bracketed expression must have the same number of variables.

15 views (last 30 days)
I am importing 25 CSV files, each csv file is imported into a table, and then the table is vertically concatenated using vertcat(). This works fine in Matlab2020b, but when I run this on Matlab2015b, I get this error, here is my code as well
rpll=cell(1,data.numberofselected); %Table of all selected csv's ordered by run number aescending
x=cell(1, numel(dir(file_location)));
for i=1:data.numberofselected
concatenated=strcat(strcat(strcat(file_location,'RUN'),int2str(data.selected_runs(i))),'.csv');
x{i}=readtable(concatenated);
end
disp(x)
rpll=vertcat(x{:}); %ERROR BEGINS HERE
All tables in the bracketed expression must have the same variable names.

Accepted Answer

Star Strider
Star Strider on 10 Mar 2021
Without knowing more about the .csv files, after reading them using readtable, use table2array to convert them to arrays, then vertically concatenate them. (I assume they all have the same number of columns, and only the variable names differ, and that is throwing the error.)
  2 Comments
waleed khalid
waleed khalid on 10 Mar 2021
Here is what my table x looks like:
Columns 1 through 11
[39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table]
Columns 12 through 22
[39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table] [39x19 table]
Columns 23 through 48
[39x19 table] [39x19 table] [39x19 table] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
Star Strider
Star Strider on 10 Mar 2021
I have no idea what ‘table x’ referrs to.
Since they all have 19 columns, you should be able to vertically concatenate them. Use the table2array function first on each table, then vertically concatenate them.
You can convert them back to a table at the end using the inverse of table2array, that being array2table. If you want to specify the variable names in the concatenated table, it will be necessary to supply your own variable names, since they will be lost in the original extractions.

Sign in to comment.

More Answers (0)

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!