Hallo, ich möchte den Wasserstand gegen Datum darstellen. Ich habe aber Problem mit der Darstellung des Datums bei x-achse! Ich danke euch für die Hilfe im Voraus.

6 views (last 30 days)
%plot water level
%% water level data
clear all
close all
fid = fopen('/Umweltdaten/Wasserstand/TuemlauAP_Herbst2017.txt'); %Dateiname for Water level
data = textscan(fid,'%s %f');
fclose(fid);
water_le = data{2};
% water_le(water_le==-999) = NaN;
for i = 1 : length(data{1}) % creat non-linear time-vector.
time(i) = datenum(sprintf('%s',string(data{1}(i))),'yyyymmddHHMMSS');
end
xticks = datenum('2017-09-07T00:00:00.0000','yyyy-mm-ddTHH:MM:SS.FFFZ'):1:datenum('2017-10-13T00:00:00.0000','yyyy-mm-ddTHH:MM:SS.FFFZ');
labels = datestr(xticks,'dd.mm');
figure
plot(time,water_le,'k','LineWidth',2);
%xlabel('time [h]')
ylabel('Water level')
xlim([min(time) max(time)])
%ylim([180 540])
set(gca,'XTick',xticks,'XTickLabel',labels);
  5 Comments
Faisal Tawashi
Faisal Tawashi on 28 Nov 2023
_The Version is R2023b.
_If I want to represent date, the scalar does not start at zero and the values of the date end approximately in the centre of the axis. Water level is raised every minute in the text file.
_The expected output on the X axis is the date from 07.09.2017 until the date 13.10.2017

Sign in to comment.

Accepted Answer

Harald
Harald on 29 Nov 2023
Hallo,
mit datetime lassen sich Datumsangaben viel schöner plotten:
time = datetime(data{1}, "InputFormat", "yyyyMMddhhmmss");
Die Daten beginnen bereits Ende August und enden Mitte November. Wenn du nur einen Ausschnitt der Daten haben möchtest, kannst du im Live Editor interaktiv zoomen oder das mit xlim angeben, dann aber mit Datumsangaben:
xlim([datetime(2017, 9, 7), datetime(2017, 10, 13)])
Viele Grüße,
Harald

More Answers (0)

Community Treasure Hunt

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

Start Hunting!