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!