how to plot data of the same date at one plot at a time
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Arif Hoq
le 22 Fév 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.
Réponses (3)
Arif Hoq
le 22 Fév 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')
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 commentaires
Arif Hoq
le 22 Fév 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
Star Strider
le 22 Fév 2022
One approach —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/902795/table.txt', 'VariableNamingRule','preserve')
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
.
0 commentaires
Seth Furman
le 23 Fév 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)
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);
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!