Reading specific cell from several csvs

3 views (last 30 days)
Hi,
Let me preface this question by saying I've just started using MATLAB recently and my familiarity with it is pretty poor.
I have just output 120 csv files with co-ordinate data in them. The first 6 rows of each csv contain redundant text regarding the output (ie date of processing, file location, sampling rate etc). Thereafter, the 7th row is filled with variable names and rows 8-13 numerical values corresponding to the relevant columnar variable. I only need one number in this entire data set, which is always at (row 13, column 3). I could obviously open every csv and manually record this value in a summary spreadsheet. I could also slit my wrists...
So my question is, is it possible to write a code that will read the 120 csv files and output the value of cell C13 into a new spreadsheet (writing each value on a new line therein)? And if so, when I'm running this code in MATLAB, will I need to run the code 120 times and select a new csv each time, or can you select all 120 csvs at once so that the code just runs a single time, over everything? And finally, can anyone direct me to the most useful source to write this code?
Many thanks Don

Accepted Answer

Daniel Shub
Daniel Shub on 19 Oct 2011
doc dlmread
I cannot tell what row and column the number you need is. But assuming C13 means column 1 and row 13.
filename = 'myfile.csv';
x = dlmread(filename, ',', 12, 0);
Getting the filenames into variable filename depends on your naming convention and directory structure. It is address pretty well in the FAQ

More Answers (1)

D
D on 19 Oct 2011
Thanks a lot Daniel, with your help I got it to work. It outputs the entire row that my value is in, but since my value is at the start of the row it will be easy enough to just delete the redundant columns after the code runs over all of the csvs.
Final code:
clear all
close all
%
for i=1:106
[filenamei,diri] = uigetfile('*.csv','Select the .csv file');
namei = strcat(diri,filenamei);
ie = dlmread(filenamei, ',', 12, 2);
dlmwrite ('output.csv',ie,'-append')
type output.csv
end
Thanks again pal.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!