Plotting of 15 years data on same graph.

11 visualizaciones (últimos 30 días)
Zunaira Akmal
Zunaira Akmal el 11 de Dic. de 2019
Comentada: Zunaira Akmal el 13 de Dic. de 2019
I have data of 15 years as i have attached here, which has the format as: Date, time, Pressure data, Temperature Data.
I want to plot the temperature dataset year over year, lets say on x-axis january-december is labeled i want to plot each year data (just Temperature) with different colored plots on the same graph.
Thanks in advance
  2 comentarios
Raj el 11 de Dic. de 2019
There is no attachment..
Zunaira Akmal
Zunaira Akmal el 11 de Dic. de 2019
Attached now.

Iniciar sesión para comentar.

Respuesta aceptada

meghannmarie el 11 de Dic. de 2019
Try something like this:
fid = fopen('Mod21_All_Inclusive_Data_Nov2019.txt');
Mod = textscan(fid,'%s %s %n %n');
fclose(fid); % Close the file
Temp = Mod{3};
DMY =cellstr(Mod{1});
HM = cellstr(Mod{2});
DMYHM = datetime(DMY,'InputFormat','MM/dd/yy') + duration(HM,'InputFormat','hh:mm');
Y = year(DMYHM);
yrs = unique(Y);
x_axis = day(DMYHM,'dayofyear') + (hour(DMYHM) + (minute(DMYHM)/60))/24;
fig = figure;
hold on
for t = 1:numel(yrs)
yr = yrs(t);
idx = yr == Y;
XTicks = nan(1,12);
XTickLabels = cell(12,1);
for n = 1:12
dt = datetime(2019,n,01);
XTicks(n) = day(dt,'dayofyear');
XTickLabels(n) = month(dt,'name');
ax = gca;
ax.XTick = XTicks;
ax.XTickLabel = XTickLabels;
  8 comentarios
dpb el 12 de Dic. de 2019
"If you do not like those long lines connecting the data gaps, you can identify the data gaps and plot those lines separately."
Or fill missing data w/ NaN and will be silently ignored by plot. Still takes finding the breakpoints but would keep one line handle per year for things like legend, linestyle etc., ...
Zunaira Akmal
Zunaira Akmal el 13 de Dic. de 2019
Thank you very much meghannmarie for your answer, it has solved my problem.
Kind regards

Iniciar sesión para comentar.

Más respuestas (1)

Hiro Yoshino
Hiro Yoshino el 11 de Dic. de 2019
Convert the date information to datetime type and extract just "months" and "days" using the functions, "month" and "day".
This way, you can remove "year" information from your dataset and thus you can line them up in the same x-axis.
  6 comentarios
dpb el 11 de Dic. de 2019
Use the new_timedata vector as x, the array of data by column as y and plot will automagically do the rest...
Have you tried anything? This is a cooperative venture, show us what you have done.
Zunaira Akmal
Zunaira Akmal el 11 de Dic. de 2019
Editada: per isakson el 13 de Dic. de 2019
If i do what you said then it will give me a plot of my complete dataset which i do not want, i want to plot data year by year, lets say first year temperature data with red color, 2nd year tempearture data with blue color and so on, i hope you are getting my point.
Yes, i have tried to plot using the code below, but now the problem is how can i extract data correspeonding to the respective data of temperature.
fid = fopen('Mod12_All_Inclusive_Data_Nov2019.txt');
Mod = textscan(fid,'%s %s %n %n');
fclose(fid); % Close the file
Temp = Mod{3};
[a,b] = histc(Year2,unique(Year2));

Iniciar sesión para comentar.


Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by