vertcat error due to Dimensions of arrays being concatenated are not consistent
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ahmed Abdulhameed M Almahdi
el 29 de Mayo de 2019
Comentada: Ahmed Abdulhameed M Almahdi
el 13 de Jun. de 2019
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
My goal to have the data look like this
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{:}))
0 comentarios
Respuesta aceptada
Pullak Barik
el 10 de Jun. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!