vertcat error due to Dimensions of arrays being concatenated are not consistent

3 Ansichten (letzte 30 Tage)
Hello,
I am trying to split text in excel file to be in multiple columns. the only problem I am facing with my code is that the dimensions of my arrays are not consistance ( vertcat error ), Is there another function I can use instead of vertcat to avoid such an error ?
thank you
this is how data looks like now
Screen Shot 2019-05-28 at 8.55.52 PM.png
My goal to have the data look like this
Screen Shot 2019-05-28 at 8.55.35 PM.png
My excel file is attached
My code:
clear
clc
x=readcell('DataOutcome.xlsx');
c=x(cellfun(@ischar,x));
split1=regexp(c, '\t', 'split');
bounds=strcat(vertcat(split1{:}))

Akzeptierte Antwort

Pullak Barik
Pullak Barik am 10 Jun. 2019
If you open 'split1' variable from the workspace and inspect its elements, it is easy to see why you are facing the issue.
What your code does is this- the rows containing the data outcome itself are read as cell arrays of length 31, where as the row containing the data for speed intervals is read as a cell array of length 30. This is because, for each row of data outcome, the first column is filled by 'Item i ' (where i is a particular row from the data outcome sub-table). Also, the headings 'Data Outcome' and 'Speed Interval' are being read as separate strings. Thus, it leads to unequal number of columns in each row, causing the mentioned error while using vertcat.
Here's a code that takes the above into consideration and manually adjusts the data-
clear;
clc;
x = readcell('DataOutcome.xlsx');
c = x(cellfun(@ischar, x));
split1=regexp(c, '\t', 'split');
bounds = vertcat(horzcat(split1{1, 1}, split1{2, :}), split1{3:10, :}, horzcat(split1{11, 1}, split1{12, :}));
The structure of the modified 'bounds' cell matrix is a little different from your goal screenshot, but only aesthetically.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by