Info

This question is closed. Reopen it to edit or answer.

How can i import both text and numeric data via Data import

2 views (last 30 days)
Currently i import the numeric data via the matlab Import data -> select colums -> Matrix. However i need to use the text data from the same while but none of the option help as this just asks me to replace the text data. The data comes from a csv file with a large name so we like to keep the import like that instead of via code.
A small snippet from the data:
;Chipset;HDD;CPU1;MEM1;
43445653;0.01;0.01;0.01;0.00;
43445654;0.02;0.01;0.01;0.01;
43445655;0.03;0.02;0.02;0.01;
43445656;0.04;0.02;0.03;0.02;
I need to use the text chipset, hdd etc in the code but i can't seem to find a way to import both of them as they just replace the text data with NaN. Any suggestions?

Answers (1)

Tim
Tim on 23 Jun 2015
Edited: Tim on 23 Jun 2015
fid = fopen('file.csv','r');
C = textscan(fid, repmat('%s',1,10), 'delimiter',';', 'CollectOutput',true);
C = C{1};
fclose(fid);
Also xlsread works on csv's:
[num txt raw] = xlsread(Filename, worksheet);
will put the numerical data in num, text data in text and all of it in a cell array "raw".

Products

Community Treasure Hunt

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

Start Hunting!