Unable to concatenate the table variables
Show older comments
hello every body.
I am new in matlab.
I want to get a vector from one .csv file but when I tried to do this I encountered problem'Unable to concatenate the table variables 'Var1' and 'Var2', because their types are double and cell'.
I attached the .csv file here.
can anyone help me overcome this problem.
thanks
6 Comments
Cris LaPierre
on 8 Jul 2021
Please also share your code.
mohamad sadeghpour
on 8 Jul 2021
Scott MacKenzie
on 8 Jul 2021
I just tried to read to duplicate your problem, but couldn't. The data were correctly read into a table and then converted to an array, a 145192x2 matrix of doubles.
dpb
on 8 Jul 2021
Which release of MATLAB are you using (output of ver at command line)?
The data detection code built into readtable has become more robust with recent releases; it's posssible that is the difference between results you found and that noted above. In particular, if the very first row of the data file for a given column isn't a number, that will cause it to be read as a cellstr() in those earlier releases but if it can be determined the column is numeric by looking at a few more rows/records in the file; it can be that the later versions will correctly identify the same input as numeric and read as double.
I didn't look at the attached zip file so whether that's a possible explanation I don't know, but the Q? of version is probably still pertinent.
You have two basic ways to go -- try detectImportOptions and the resulting import options object and see if that succeeds or, use str2double to convert the column in question after reading the file as is.
dpb
on 8 Jul 2021
I'll add, however, that solving the problem aside, more than likely converting the input table to an array isn't going to be needed -- or, if an array is indeed the better choice over a table, then use readmatrix instead.
Which, now that that thought comes to mind, that's another thing to try and see if it does any better than readtable. If the issue is something like I guessed at above, it will probably fail because the same search code is going to be in the one release.
Oh! I think I now recall once looking and discovering that readmatrix ends up calling readtable to do the dirty work, anyways...
Walter Roberson
on 8 Jul 2021
The more advanced automatic scanning was not present in R2018b; you should add a detectImportOptions() call.
Accepted Answer
More Answers (1)
Sulaymon Eshkabilov
on 9 Jul 2021
FName='myout.csv';
D= readtable(FName);
DATA= [D.Var1, D.Var2];
Categories
Find more on Data Type Conversion 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!