How do I import .csv file into MATLAB that has multiple values per field? MATLAB is not importing this properly.
Show older comments
So I have a .csv file, that has 14 rows and 120 columns. I need to import this .csv file into MATLAB. Now the problem is that there are 128 values per each field in this .csv file, all of which has to be imported properly (I'm attaching picture of how the data looks here below, you can see there are multiple values per field). I tried importing it as a .csv but it doesn't give me any of these values. I also tried converting to .txt and importing that, but it doesn't give all the values either. Is there any way I could import this data properly into MATLAB?

2 Comments
Stephen23
on 16 Nov 2020
@Zuha Yousuf : please upload a sample file by clicking on the paperclip button.
Zuha Yousuf
on 16 Nov 2020
Answers (1)
Walter Roberson
on 10 Nov 2020
S = fileread('YourFileNameHere.csv');
S = regexrep(S, {'\[|\]', '\s+'}, {'', ','});
data = cell2mat(textscan(S, '')); %format '' tells it to figure out number of columns
Categories
Find more on Standard File Formats 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!