Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

1 次查看(过去 30 天)
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?

回答(1 个)

Tim
Tim 2015-6-23
编辑:Tim 2015-6-23
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".

此问题已关闭。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by