Unable to concatenate the table variables

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

Please also share your code.
this is a simple code
c=readtable('myout.csv');
D=table2array(c);
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.
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.
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...
The more advanced automatic scanning was not present in R2018b; you should add a detectImportOptions() call.

Sign in to comment.

 Accepted Answer

hello every body
I solve this problem myself by removing spaces in the .csv file.
thanks every body

More Answers (1)

FName='myout.csv';
D= readtable(FName);
DATA= [D.Var1, D.Var2];

Categories

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!