"error using horzcat demonstrates" Please help
Show older comments
The file is 2131x1 and it has some data on it that's not available. How can I bypass the error without changing the data itself
The code:
readtable("BWBnontidal2013-2019.xlsx",'ReadVariableNames',false);
data1 =xlsread('BWBnontidal2013-2019.xlsx','A:A');
data2 =xlsread('BWBnontidal2013-2019.xlsx','C:C');
data3 =xlsread('BWBnontidal2013-2019.xlsx','D:D');
data4 =xlsread('BWBnontidal2013-2019.xlsx','F:F');
data5 =xlsread('BWBnontidal2013-2019.xlsx','G:G');
data6 =xlsread('BWBnontidal2013-2019.xlsx','K:K');
data7 =xlsread('BWBnontidal2013-2019.xlsx','M:M');
data8 =xlsread('BWBnontidal2013-2019.xlsx','O:O');
data9 =xlsread('BWBnontidal2013-2019.xlsx','P:P');
data=[data1 data2 data3 data4 data5 data6 data7 data8 data9];
The message back:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
1 Comment
Adam
on 15 Mar 2021
Don't try to concatenate the data if its dimensions are not consistent. How you want to deal with that inconsistency I have no idea. Depends entirely what the data is and what is inconsistent about it. But the error can only be by-passed by either not doing it or pre-processing the data1 - data9 in whatever way is needed to make it possible.
Answers (1)
Cris LaPierre
on 15 Mar 2021
Your code is a bit repetative. You use readtable, but don't capture the results. You then re-load the data one column at a time using xlsread.
I would use readtable to read into the entire spreadsheet. This will create all variables with the same number of rows, replacing any missing data either with a value you specify, or with the missing value. You can then access the variables you want directly.
data = readtable("BWBnontidal2013-2019.xlsx",'ReadVariableNames',false);
Categories
Find more on Data Import from MATLAB 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!