Plot in a script with three time series, each series has to be a different color

1 Ansicht (letzte 30 Tage)
I made a plot with three different time series, each series has to be plotted with lines and each series has a different color.
% temperature time series
% loading three different temperature gauges in
% North Carolina (Boone)
% loading temperature data from 3 different locations
tempdat = load('StreamTemp.dat');
col1 = tempdat(:,1);
tempdat = tempdat-32;
tempdat = tempdat * 5;
tempdat = tempdat / 9;
tempdat(:,1) = col1;
% plot the data we converted
x = col1;
y = tempdat(:,2:4);
plot(x,y);
xlabel('Time(days)');
ylabel('Temperature(C)');
title('Temperature Gauges in North Carolina');
  1 Kommentar
dpb
dpb am 20 Apr. 2020
...
col1 = tempdat(:,1);
tempdat = tempdat-32;
tempdat = tempdat * 5;
tempdat = tempdat / 9;
tempdat(:,1) = col1;
The above just writes the same data back to column one of the tempdat array because variable col1 was never modified---what you're looking for is:
tempdat(:,1)=5*(tempdat(:,1)-32)/9; % convert FtoC column 1 tempdat array
But, you follow this with
x = col1;
y = tempdat(:,2:4);
plot(x,y);
so it looks like column 1 isn't a temperature after all but maybe a time variable???
The plot call you have will draw three lines in different colors so that part of the question should be answered.
What we need to know is what the actual data in the file is as what you've written seems inconsistent at best.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Vimal Rathod
Vimal Rathod am 23 Apr. 2020
Hi,
If you try to plot any two timeseries plots in the same plot using "hold on" you would always get plots with different colors and that would be automatically done by MATLAB.
But if you want to specify which color each plot should have, you could refer to the following link to know more about the color property of plot.
To know more about "hold" refer to the following link
Refer to the below link for more details on plotting timeseries data

Community Treasure Hunt

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

Start Hunting!

Translated by