Plot multiple columns of table with datetime
38 ビュー (過去 30 日間)
古いコメントを表示
Hi, I want to plot multiple (all) columns of a table.
The x axis should be the datetime corresponding to the variables of the column.
My table is in this shape:
P = array2table(rand(288,3),'VariableNames', ["generator", "consumer", "storage"]);
How I was possible to plot all data was:
plot(fig.probax(3), P, P.Properties.VariableNames);
I have a datetime Array:
current_time = datetime('now','Format','yyyy-MM-dd HH:mm');
current_time.Minute = 15 * round(current_time.Minute/15);
datetimeArray = current_time + hours(0:0.25:3*24-2^(-8)).';
And I would like to have the datetimeArray as my x axis but I don't know how I use it in my plot function.
I already know how to show the datetime array in my x axis with
datetick(fig.probax(3),'x', 'HH:mm', 'keeplimits', 'keepticks');
How do I set the x axis of multiple columns of a table?
0 件のコメント
採用された回答
Voss
2023 年 10 月 18 日
編集済み: Voss
2023 年 10 月 18 日
P = array2table(rand(288,3),'VariableNames', ["generator", "consumer", "storage"]);
current_time = datetime('now','Format','yyyy-MM-dd HH:mm');
current_time.Minute = 15 * round(current_time.Minute/15);
datetimeArray = current_time + hours(0:0.25:3*24-2^(-8)).';
% ax = fig.probax(3);
ax = gca();
plot(ax, datetimeArray, P{:,:});
3 件のコメント
dpb
2023 年 10 月 18 日
P = array2table(rand(288,3),'VariableNames', ["generator", "consumer", "storage"]);
current_time = datetime('now','Format','yyyy-MM-dd HH:mm');
current_time.Minute = 15 * round(current_time.Minute/15);
datetimeArray = current_time + hours(0:0.25:3*24-2^(-8)).';
% ax = fig.probax(3);
hAx=axes;
plot(hAx, datetimeArray, P.Variables); % alternative syntax
その他の回答 (1 件)
dpb
2023 年 10 月 18 日
Use a @doc:timetable instead and then geth stackedplot for free that does it all for you. Use the target figure/panel to place it where you wish in the app; I just let it default for demo as can't create uifgure here.
V=rand(288,3);
current_time = datetime('now','Format','yyyy-MM-dd HH:mm');
current_time.Minute = 15 * round(current_time.Minute/15);
datetimeArray = current_time + hours(0:0.25:3*24-2^(-8)).';
ttP=array2timetable(V,'RowTimes',datetimeArray,'VariableNames', ["generator", "consumer", "storage"]);
stackedplot(ttP)
If you really, really must have the three on one plot, then
figure
subplot(2,1,1)
plot(ttP.Time,ttP{:,ttP.Properties.VariableNames}) % use {} dereferencing table
subplot(2,1,2) % or
plot(ttP.Time,ttP.Variables) % use all variables shorthand
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!