필터 지우기
필터 지우기

Plotting data from text file

조회 수: 1 (최근 30일)
Cagas Akalin
Cagas Akalin 2016년 10월 13일
댓글: Cagas Akalin 2016년 10월 13일
Dear All,
The problem that I am dealing with is to obtain a plot from a text file has 5615917 lines of data. The shorthaned content of the data file that I am dealing with looks like as follows.
channel names:
09/07/2016 06:20:09 PM - Thermocouple - SC1Mod2_ai2
start times:
9/7/2016 18:20:13.504689
dt:
0.010000
data:
8.857533E+1
8.857165E+1
8.856430E+1
8.857165E+1
8.856798E+1
8.857165E+1
8.856798E+1
8.857900E+1
8.856430E+1
8.857165E+1
8.857165E+1
8.856798E+1
8.856430E+1
8.856798E+1
.
.
.
2.635587E+1
2.635209E+1
2.635965E+1
2.635587E+1
2.635209E+1
2.635965E+1
2.635965E+1
2.635209E+1
2.635587E+1
2.635965E+1
2.634832E+1
and the code that I use is
clear all
close all
clc
fileID = fopen('ThermocoupleCombined.txt','r');
Crude_Data = textscan(fileID,'%f','HeaderLines','2');
fclose(fileID);
C = transpose(0:0.01:0.01*(length(Crude_Data{1})-1));
plot(C,Crude_Data{1})
The code above draws the data up to 76757 and the rest is not included inside "Crude_Data" and not plotted.
Can you please give me your suggestions regarding the problem I have?
  댓글 수: 8
Cagas Akalin
Cagas Akalin 2016년 10월 13일
class of B is cell while class of C is double. Also you can find the file in the link below.
https://www.dropbox.com/s/08mpjcc542cx0de/ThermocoupleCombined.txt?dl=0
KSSV
KSSV 2016년 10월 13일
That's why error popped out. What are respective sizes? Mean while I will check your data.

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2016년 10월 13일
Dear friend
Check the line 76807..there is change in the format.....So MATLAB is plotting fine from line 8 to 76807. You have to change the pattern of reading the file using textscan().
  댓글 수: 2
KSSV
KSSV 2016년 10월 13일
fileID = fopen('ThermocoupleCombined.txt','r');
% Crude_Data = textscan(fileID,'%f','HeaderLines','2');
% Crude_Data = textscan(fileID,'%f','HeaderLines',7);
Crude_Data = textscan(fileID,'%s','delimiter','\n');
C = Crude_Data{1} ;
fclose(fileID);
IdxC = strfind(C, 'data');
Idx = find(not(cellfun('isempty', IdxC)));
% split the data
data1 = C(Idx(1)+1:Idx(2)-9) ;
data1 = data1(~cellfun('isempty',data1)) ; % remove empty cells if any
data2 = C(Idx(2)+1:end) ;
% convert to double
data1 = sprintf('%s*', data1{:});
data1 = sscanf(data1, '%f*');
t1 = 0:0.01:0.01*(length(data1)-1);
data2 = sprintf('%s*', data2{:});
data2 = sscanf(data2, '%f*');
t2 = 0:0.01:0.01*(length(data2)-1);
plot(t1,data1,'r') ;
hold on
plot(t2,data2,'b') ;
Cagas Akalin
Cagas Akalin 2016년 10월 13일
Dear Kolukula,
Thanks for your help and suggestions. Actually, the .txt file read by Matlab is the combination of two with their individual headers. I copied one and pasted it end of the other however, fortunately I forgot deleting the header part of subsequent data. After your warning, recreating merged file without header part in between allowed the code plot the figure without any error.
Thank you very much again for your time.
Best wishes.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by