Temperature vs time plot

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 日
What is class of temp and time? What are their sizes?
Michela Longhi
Michela Longhi 2017 年 6 月 14 日
they are
00:00:00 26
00:00:01 26
00:00:02 26
00:00:03 26
00:00:04 26
00:00:05 26
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 日

0 投票

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 日

0 投票

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.

カテゴリ

質問済み:

2017 年 6 月 14 日

回答済み:

2017 年 6 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by