필터 지우기
필터 지우기

Temperature vs time plot

조회 수: 18 (최근 30일)
Michela Longhi
Michela Longhi 2017년 6월 14일
답변: Peter Perkins 2017년 6월 20일
I want to plot data vs temperature data from an external file:
fileID_A=fopen('discesa_salita.txt');
A = textscan(fileID_A,'%D %s');
time_A=A{1};
time=time_A(37:210) ;
temp_A=A{2};
temp=temp_A(37:210) ;
figure()
plot(time, temp);
But Matlab said: "Error using plot Invalid second data argument", what am I doing wrong?
  댓글 수: 4
KSSV
KSSV 2017년 6월 14일
Class of time? class(time) gives what output? You need to convert it to certain format to plot.
Michela Longhi
Michela Longhi 2017년 6월 14일
I don't know... how can I convert to seconds, for example?

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

답변 (2개)

KSSV
KSSV 2017년 6월 14일
time = {'00:00:00'
'00:00:01'
'00:00:02'
'00:00:03'
'00:00:04'
'00:00:05'} ;
temp = [26 ; 26 ; 26;26;26;26] ;
plot(second(time),temp) ;

Peter Perkins
Peter Perkins 2017년 6월 20일
You are likely to be much happier using readtable than textscan. Given that you've used '%D %s' as the format, your temperatures are read in as a cell array of char vectors, and plot isn't going to like that.
Try something like this:
t = readtable('discesa_salita.txt','ReadVariableNames',false); % best guess
t.Var1 - timeofday(t.Var1); % timestamps read as datetimes, convert to durations
t = t(37:210,:);
plot(time, temp);
Depending on what version of MATLAB, you may need to give readtable a format.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by