Sub-sampling with mean value of a datasets including time
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello everyone,
I have an excel datasets containing parameters: data_x, data_y, and time in date format (see attached file). My intention is to get a sub-sampled datasets from those datasets, and plot them properly using scatter plot of data_x, data_y with colormap of the time. Please see the logic as follow:
Let's say, the new sub-sampled data is the mean of six rows as shown above. Anyone has suggestion to get it and also the scatter plots with time evolution of the colorbar?
Thank you!
댓글 수: 0
채택된 답변
Star Strider
2024년 10월 11일
편집: Star Strider
2024년 10월 12일
I am not certain how the means whould be calculated. If you want to calculatee the means of every six rows, that is relatively straightforward.
Try this —
T1 = readtable('data_sheet.xlsx')
VN = T1.Properties.VariableNames;
cols = size(T1,1)/6;
idx = ones(6,fix(cols)) .* (1:fix(cols));
numel(idx)
T2 = T1(1:numel(idx),:);
T3xyc = accumarray(idx(:), (1:numel(idx)).', [], @(x){mean(T2{x,1:2})});
T3xy = cell2mat(T3xyc);
T3dn = accumarray(idx(:), (1:numel(idx)).', [], @(x)mean(datenum(T2{x,3})));
T3t = datetime(T3dn,'ConvertFrom','datenum');
T3 = table(T3xy(:,1), T3xy(:,2), T3t, 'VariableNames',VN)
[tmin,tmax] = bounds(T3.time)
doy = day(T3.time, 'dayofyear');
doy = doy + cumsum([0; diff(doy)<0])*max(doy);
doyHH = doy + hour(T3.time)/24 + minute(T3.time) + second(T3.time); % Day (Of Year) + Hour (24 Hour) + Minute + Second
% figure
% plot(T1.t, doy)
% grid
figure
scatter(T3.data_x, T3.data_y, 10, doyHH, 's', 'filled')
grid
colormap(turbo)
hcb = colorbar;
cbtixidx = ismember(doyHH, hcb.Ticks);
hcb.TickLabels = string(T1.time(cbtixidx));
hcb.FontSize = 8;
xlabel('data\_x')
ylabel('data\_y')
title('Scatter Plot Coloured By Date')
figure
scatter3(T3.data_x, T3.data_y, doyHH, 10, doyHH, 's', 'filled')
grid on
colormap(turbo)
hcb = colorbar;
cbtixidx = ismember(doyHH, hcb.Ticks);
hcb.TickLabels = string(T1.time(cbtixidx));
hcb.FontSize = 8;
Ax = gca;
% Ax.ZTick
ztixidx = ismember(doyHH, Ax.ZTick);
tl = interp1(doyHH, T3.time, Ax.ZTick, 'linear','extrap');
Ax.ZTickLabel = string(tl);
Ax.ZAxis.FontSize = 8;
xlabel('data\_x')
ylabel('data\_y')
zlabel('Time')
title('3D Scatter Plot Coloured By Date')
EDIT — (12 Oct 2024 at 00:03)
Initially forgot to calculate the mean values of ‘T1’.
.
댓글 수: 4
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Colormaps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!