how to plot data of the same date at one plot at a time

2 Ansichten (letzte 30 Tage)
MA
MA am 22 Feb. 2022
Beantwortet: Seth Furman am 23 Feb. 2022
Having the attached table, if we would like to plot that two variables (NE8, GDALT) for each specific value of the variable "Date" in a different plot, to get at the end a plot for each specific date, how can we do that?
Th eplots should have the variable NE8 on the x-axis, and the variable GDALT on the y-axis, and this is should be for each different value of the variable "Date" that we have, i.e in this table there are 32 different dates so we would like to have 32 differnet plots each one plotting the NE8 vs GDALT data for that date.
  2 Kommentare
Arif Hoq
Arif Hoq am 22 Feb. 2022
what kinds of data do you want to plot ? GDALT,NE8,solarT,DST,Bin ? which one? what is specific date ? there are 3 date values.
MA
MA am 22 Feb. 2022
Thank you for replaying back. The plots would be between the NE8 column and GALT column, according to the values stored in the variable "Date".

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Arif Hoq
Arif Hoq am 22 Feb. 2022
A=readtable('table.txt','ReadVariableNames',true);
AA=table2array(A);
year=A.YEAR;
month=A.MONTH;
day=A.DAY;
dates = datenum([year,month,day]);
% dat=num2str(dates);
t = datetime(dates,'ConvertFrom','datenum','InputFormat','yyyy-MM-dd')
t = 289×1 datetime array
15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020 15-Jan-2020
GDALT=AA(:,6);
NE8=AA(:,7);
figure(1)
plot(t,GDALT)
datetick('x', 'mmm dd', 'keepticks')
xtickangle(45)
xlabel('date')
ylabel('GDALT')
title('Date vs GDALT')
figure(2)
plot(t,NE8)
datetick('x', 'mmm dd', 'keepticks')
xtickangle(45)
xlabel('date')
ylabel('NE8')
title('Date vs NE8')
  2 Kommentare
MA
MA am 22 Feb. 2022
I apreciate you help, but this is not what I am sking about. Th eplots should have the variable NE8 on the x-axis, and the variable GDALT on the y-axis, and this is should be for each different value of the variable "Date" that we have, i.e in this table there are 32 different dates so we would like to have 32 differnet plots each one plotting the NE8 vs GDALT data for that date.
Arif Hoq
Arif Hoq am 22 Feb. 2022
i did not get 32 different dates. you can see the unique function. Total 289 dates, but 7 unique dates. so you can get 7 single points withe respect to x axis(NE8) and y axis(GDALT). as you said you need all plots(here 7 plots), so you can get 7 figures.check this code.
A=readtable('table.txt','ReadVariableNames',true);
AA=table2array(A);
year=A.YEAR;
month=A.MONTH;
day=A.DAY;
dates = datenum([year,month,day]);
% dat=num2str(dates);
t = datetime(dates,'ConvertFrom','datenum','InputFormat','yyyy-MM-dd');
[C,ia,ic]=unique(t);
GDALT=AA(:,6);
NE8=AA(:,7);
idxGDALT=GDALT(ia);
idxNE8=NE8(ia);
for plotId = 1 : 7
figure(plotId) ;
plot(idxNE8(plotId), idxGDALT(plotId),'o') ;
end

Melden Sie sich an, um zu kommentieren.


Star Strider
Star Strider am 22 Feb. 2022
One approach —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/902795/table.txt', 'VariableNamingRule','preserve')
T1 = 289×13 table
YEAR MONTH DAY HOUR MIN GDALT NE8 Date HOUR2 Date2 solarT DST Bin ____ _____ ___ ____ ___ _____ ________ ________ _____ ________ ______ ___ ___ 2020 1 15 3 7 300 2.65e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 7 315 3.14e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 7 330 3.53e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 7 345 2.94e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 7 360 2.35e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 7 375 1.74e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 7 390 1.3e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 18 300 3.26e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 18 315 3e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 18 330 2.81e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 18 345 2.38e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 18 360 1.93e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 18 375 1.2e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 18 390 9.5e+10 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 29 300 2.33e+11 2.02e+11 3 2.02e+11 73.5 -2 2 2020 1 15 3 29 315 2.99e+11 2.02e+11 3 2.02e+11 73.5 -2 2
Datev = datetime(T1{:,1:6});
[G,ID] = findgroups(day(Datev,'dayofyear'));
NumDates = numel(ID);
NumCols = fix(sqrt(NumDates)); % Design Subplot Array
NumRows = ceil(NumDates/NumCols); % Design Subplot Array
figure
for k = 1:NumDates
subplot(NumRows, NumCols, k)
DateIdx = G == k;
DateName = Datev(DateIdx);
DateName.Format = 'yyyy-MM-dd';
plot(T1.NE8(DateIdx), T1.GDALT(DateIdx))
grid
xlabel('NE8')
ylabel('GDALT')
title(string(DateName(1)))
xlim([0 5]*1E11) % Plot All To Same Scale
ylim([200 500]) % Plot All To Same Scale
end
.

Seth Furman
Seth Furman am 23 Feb. 2022
Adding to Star Strider's answer, consider using tiledlayout('flow') for creating the plots.
t = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/902795/table.txt");
t.Date = datetime(string(t.Date), "InputFormat", "uuuuMMddHHmm");
dates = unique(t.Date)
dates = 32×1 datetime array
15-Jan-2020 03:07:00 15-Jan-2020 03:18:00 15-Jan-2020 03:29:00 15-Jan-2020 03:39:00 15-Jan-2020 03:50:00 15-Jan-2020 04:01:00 15-Jan-2020 04:11:00 15-Jan-2020 04:22:00 15-Jan-2020 04:33:00 15-Jan-2020 04:43:00 15-Jan-2020 04:54:00 21-Jan-2020 03:07:00 21-Jan-2020 03:18:00 22-Jan-2020 03:07:00 22-Jan-2020 03:18:00 22-Jan-2020 03:29:00 26-Feb-2020 03:13:00 26-Feb-2020 03:29:00 26-Feb-2020 03:45:00 27-Feb-2020 03:15:00 27-Feb-2020 03:31:00 27-Feb-2020 03:47:00 28-Feb-2020 03:31:00 28-Feb-2020 03:47:00 28-Feb-2020 04:03:00 28-Feb-2020 04:19:00 28-Feb-2020 04:35:00 28-Feb-2020 04:51:00 29-Feb-2020 03:15:00 29-Feb-2020 03:31:00
tl = tiledlayout('flow');
for i = 1:length(dates)
tDate = t(t.Date == dates(i), :);
plot(nexttile, tDate.NE8, tDate.GDALT);
xlabel("NE8");
ylabel("GDALT");
title(string(dates(i)));
end
linkaxes(tl.Children);

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by