MATLAB Answers

How to convert a .csv file of cell array type to double?

73 views (last 30 days)
hello_world
hello_world on 4 Jul 2018
Reopened: hello_world on 13 Jul 2018
I have multiple .csv files of type Cell. I have attached 3 of these files for illustration and a data.csv file of type double. These files are located in path C:\Users\Anonymous\Documents\MATLAB
I want to load them one-by-one and convert them to type double and then to save them in the same path. I tried different ways, such as, cell2mat, str2mat, str2double, str2num, cell2csv (file exchange), etc. but without success. cell2mat gives error, and str2num convert everything in the file to NaN. Yes, it is true that my .csv files have characters like !, ., _, etc., but I still need to find a way to use the same file name and do the conversion to type double/numeric.
  7 Comments
hello_world
hello_world on 4 Jul 2018
@Stephen Cobeldick My actual task is that I want to convert File.A_label.csv as given in my example to type double such that the converted file does not contain numeric entries, such as, 1s, 2s, 3s, etc.
Now, you are asking me why I want to do it? I think you ask this because once you know what is the next goal, you will switch to that problem rather than advising me how to do this conversion. I just want to see if this type of conversion is possible. I am not looking for help in post achieving type double conversion.
So I do not think that it is an XY problem as you have referenced. Walter Roberson's solution is almost close but not exactly what I want to achieve. Frankly speaking, I do not think that it is even possible.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 4 Jul 2018
Depending on what you are doing, you might want to use categorical(), or might simply want to use findgroups().
Note that several of the classification and neural network routines are happy to take a cell array of strings as labels.
  7 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!