フィルターのクリア

How to add table to figure with subplots?

37 ビュー (過去 30 日間)
Nicholas Kavouris
Nicholas Kavouris 2023 年 1 月 17 日
回答済み: Nehemiae 2023 年 2 月 9 日
I am trying to add a UI table to the figure attached. the table should be located where the bottom blank graph is. Each time attempting to run my script i generate the following error:
Error using uitable
Functionality not supported with figures created with the figure function.
Here is my code, any advice appreciated
fileSummary=uifigure('Name','File Summary','WindowState','normal','Visible','on');
subplot(4,1,1);
grid on;
xlabel('Time (s)');
yyaxis left;
plot(cookdata.TempF,'Color','r','LineWidth',1,"DisplayName","Probe Temp F");
hold on;
yticks('auto');
ylabel('Temperature (F)',Color="r");
set(gca,'YColor','r');
yyaxis right;
yticks('auto');
ylabel('PWM/100 || RPM','Color','#FAA533');
set(gca,'YColor','#FAA533')
plot(cookdata.AugerPWM./100,'LineStyle','-','Color','#FAA533',"DisplayName","Auger PWM");
plot(cookdata.AugerRPM./1000,'LineStyle','-','Color','#21ABDE',"DisplayName","Auger RPM");
plot(cookdata.FanPWM./100,'LineStyle','-','Color','#94918D',"DisplayName","Fan PWM");
legend('Location','southoutside','Orientation','horizontal')
subplot(4,1,2);
yyaxis left
ylim([-2 2])
xlabel('Time (s)');
ylabel('PID Value');
yticks('auto');
plot(cookdata.P,'DisplayName','P','Color', [.13 .13 .13],'LineStyle','-');
hold on;
plot(cookdata.I,'DisplayName','I','Color',[0.9290 0.6940 0.1250],'LineStyle','-');
plot(cookdata.D,'DisplayName','D','Color',[0 0.4480 0.7410],'LineStyle','-');
plot(cookdata.U,'DisplayName','U','Color','r','LineStyle','-');
yyaxis right;
plot(cookdata.TempF,'DisplayName','Temp F','Color','#E0932C','LineWidth',1);
ylabel('Temperature (F)');
grid on;
legend('Location','southoutside','Orientation', 'horizontal');
hold off;
subplot(4,1,3);
grid on;
plot(cookdata.grillState,'DisplayName','Grill State','Color','#D95319');
hold on;
plot(cookdata.GPstatus,'DisplayName','Glowplug Status','LineStyle','--','Color','#77AC30');
xlabel('Time (s)');
yticks(0:1:5)
legend('Location','southoutside','Orientation','horizontal')
subplot(4,1,4);
rownames={'Date','Grill Name','Grill Model','FW','Duration','Set Temp','Time to Temp','Time To Steady','Overshoot','Start Temp','File Name'};
t=table(cook.date,cook.grillName,cook.grillModel,cook.FW,cook.duration,cook.setPoint,cook.minstotemp,cook.minstosteady,cook.overshoot,cook.startTemp,cook.dataName,'VariableNames',rownames);
uitable("Data",t{:,:},'ColumnName',t.Properties.VariableNames)

回答 (1 件)

Nehemiae
Nehemiae 2023 年 2 月 9 日
It is my understanding that you require the "uitable" to appear in the 4th subplot region on the "uifigure". I can see that the "uifigure" fileSummary has been created, but since it is not set as the parent of anything, further calls to plot, subplot, etc. create a new figure window.
This can be avoided by setting the required parent/passing the required axis handle. Now, as for the "uitable" it cannot be linked to an axis. Hence the best way to put it in the required region, is to get the position of the subplot region and set the "uitable" to this position.
For all the plots to appear on the same “uifigure”, all the subplots must be set with the ‘Parent’ property as fileSummary, and the required axis handles must be passed to plot, grid, hold, etc.
fileSummary = uifigure('Name', 'File Summary', 'WindowState', 'normal', 'Visible', 'on', 'AutoResizeChildren', 'off'); % Subplots on uifigure requires AutoResizeChildren property off
% Change other subplots accordingly
h1 = subplot(4, 1, 1, 'Parent', fileSummary); % Set parent as uifigure
grid(h1, 'on');
xlabel(h1, 'Time (s)'); % Plot on required axis
yyaxis(h1, 'left');
plot(h1, cookdata.TempF, 'Color', 'r', 'LineWidth', 1, "DisplayName", "Probe Temp F");
hold(h1, 'on');
yticks(h1, 'auto');
ylabel(h1, 'Temperature (F)', Color = "r");
set(h1, 'YColor', 'r');
yyaxis(h1, 'right');
yticks(h1, 'auto');
ylabel(h1, 'PWM/100 || RPM','Color', '#FAA533');
set(h1, 'YColor', '#FAA533')
plot(h1, cookdata.AugerPWM ./ 100, 'LineStyle', '-', 'Color', '#FAA533', "DisplayName", "Auger PWM");
legend(h1, 'Location', 'southoutside', 'Orientation', 'horizontal');
% Your code here with required changes ...
% Get position of required subplot region and delete it
h4 = subplot(4, 1, 4, 'Parent', fileSummary);
pos = get(h4, 'Position');
un = get(h4, 'Units');
delete(h4);
rownames = {'Date', 'Grill Name', 'Grill Model', 'FW', 'Duration', 'Set Temp', 'Time to Temp', 'Time To Steady', 'Overshoot', 'Start Temp', 'File Name'};
t = table(cook.date, cook.grillName, cook.grillModel, cook.FW, cook.duration, cook.setPoint, cook.minstotemp, cook.minstosteady, cook.overshoot, cook.startTemp, cook.dataName, 'VariableNames', rownames);
uitable(fileSummary, "Data", t{:,:}, 'ColumnName', t.Properties.VariableNames, 'Units', un, 'Position', pos); % Set uitable's parent as the uifigure and position as desired
Here are a few links that can help in understanding the above code - Graphics Object Hierarchy for how graphical objects are linked to each other, and the MATLAB Central answer for the subplot workaround for “uitable”.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by