Converting raw gas chromatograph data to a matrix

My gas chromatograph has the ability to output .csv files and I can open them in excel. Excel has the ability to use the text to columns function and remove the comma, allowing the csv data to be separated into two columns. However, I would much rather do this in MATLAB and have everything be automated. But when I try and use the csvread function there is an error because when importing the data from excel to MATLAB, there is now quotation marks surrounding my csv's.
For example, my first value which I need separated is: "0.00333333333333333,869721.594606312"
I know there is a simple solution either using strrep or csvread, but I can't seem to get it right. Any help is appreciated, thank you.
Thanks!

 Accepted Answer

If your version of Excel can read it, then the MATLAB xlsread function should be able to as well.

7 Comments

Yes that works, but only partially. Now the data is imported into matlab and now I have a 1 column, 5000 row cell and now the cell has values such as '0.00333333333333333,869721.594606312'. How do I go on further to separate these two values and separate them into two columns?
Can you attach your file (or a shorter version if it’s too long to attach all of it)?
If we have the file we can experiment with it. That beats guessing at solutions.
Sure! Here it is, attached.
I wanted to do this without loops but couldn’t.
It works, though:
[d,s,r] = xlsread('Nicholas Frank SIGNAL1.csv');
ss = cellfun(@(x) strsplit(x,','), s, 'Uni',0);
for k1 = 1:size(ss,1)
sn{k1} = str2num(char(ss{k1}));
end
GC1 = cell2mat(sn)';
Chk = GC1(1:5,:); % Check Data
The ‘GC1’ double array is the output. I would save it as a .mat file to avoid having to go through this each time you want to use the data. The nice thing about a .mat file is that you can also include other information about that experiment as additional variables of any class in the file itself.
The ‘Chk’ assignment is informational only to let you see the first few lines of the imported data.
The textscan() approach works fine; I tested it.
hHanks so much! This works :).

Sign in to comment.

More Answers (1)

fid = fopen('SIGNAL1.CSV');
C = textscan(fid,'"%f,%f"', 'CollectOutput', 1);
fclose(fid);
YourData = C{1};

1 Comment

Brilliant!
I wish I’d thought to include the double quotes and the comma in the format descriptor when I experimented with textscan. That eliminates both as problems, with no further data manipulation needed. Something to remember.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!