Quick question regarding CSV file reading.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
benjamin finsås
am 3 Mai 2021
Kommentiert: Jeremy Hughes
am 4 Mai 2021
I have two csv files with only one colum each. I want to extract only the first number (measurement counter) and Sensor output last (V), i dont care about the water temp. The second file has less measurements (rows) than the first, so i need to chop out some measurements (rows). Preferably i want to start from a specific row, for example row 3-9 in CSVfile1 and row 4-8 in CSVfile2. Can anyone explain how i could do this, if its even possible?
I also need to plot the two tables/arrays in a same graph.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/605390/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/605395/image.png)
Best regards,
-Ben
4 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 3 Mai 2021
hello
my quick suggestion to the quick question
fid=fopen('cycle1.csv');
e=textscan(fid,'%s','headerlines',1);
e_splitted = split(e{1},',');
outdata = cellfun(@str2num,strrep(e_splitted, '"', '')); % remove double quotes & convert string to num
% get my Counter and Sensor_Output data
start_row = 3;
stop_row = 9;
Counter_Output = outdata(start_row:stop_row,1);
Sensor_Output = outdata(start_row:stop_row,2);
6 Kommentare
Weitere Antworten (2)
EmirBeg
am 3 Mai 2021
Bearbeitet: EmirBeg
am 3 Mai 2021
Data1 = readtable('cycle1.csv');
Data2 = readtable('cycle2.csv');
t1 = table2array(Data1(:,1));
SensorOutput1 = table2array(Data1(:,2));
t2 = table2array(Data2(:,1));
SensorOutput2 = table2array(Data2(:,2));
SizeDiff = size(SensorOutput1,1)-size(SensorOutput2,1);
StartingRow = 1; %set the row that you want to start with
t1 = t1(StartingRow:size(t1,1)-SizeDiff);
SensorOutput1 = SensorOutput1(StartingRow:size(SensorOutput1,1) - SizeDiff);
plot(t1,SensorOutput1);
hold on;
plot(t2,SensorOutput2);
hold off;
1 Kommentar
Jeremy Hughes
am 4 Mai 2021
This is a bit cumbersome:
t1 = table2array(Data1(:,1));
SensorOutput1 = table2array(Data1(:,2));
t2 = table2array(Data2(:,1));
SensorOutput2 = table2array(Data2(:,2));
It would be easier just to use dynamic variable indexing:
t1 = Data1.(1);
SensorOutput1 = Data1.(2);
t2 = Data2.(1);
SensorOutput2 = Data2.(2);
Jeremy Hughes
am 4 Mai 2021
I'd do this:
opts = detectImportOptions('cycle1.csv','Delimiter',',','VariableNamingRule','preserve');
opts.SelectedVariableNames = opts.VariableNames(1:2);
opts.DataLines = [3 9];
T1 = readmatrix('cycle1.csv',opts);
opts.DataLines = [4 8];
T2 = readmatrix('cycle2.csv',opts);
I'll leave the plotting to you.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!