Hello,
I have this code:
subplot(2,2,1)
yplot_balance = table2array(Tablecalc(:,6));
xplot_balance = table2array(Tablecalc(:,8));
plot(xplot_balance,yplot_balance, '.-')
xlabel('Fecha de cierre de la operación')
ylabel('Total equity')
grid on
subplot(2,2,2)
yplot_r = table2array(Tablecalc(:,5));
xplot_r = table2array(Tablecalc(:,8));
plot(xplot_r,yplot_r, '.-')
xlabel('Fecha de cierre de la operación')
ylabel('Resultado en Rs')
grid on
newfig = uifigure('name','Datos');
uit = uitable(newfig,'Data',Tablecalc, 'Position', [20 20 500 150]);
With that, so far I have been able to create plots in the same figure and insert a table to a separate figure.
However I am trying to insert in the plots' figure the table. The table has ints, doubles, strings and datetime values (I tried to convert it to an array or cells and did not work either).
In each method I have tried I get this error: Error using uitable Functionality not supported with figures created with the figure function. For more information, see Graphics Support in App Designer.
Some help please!

 채택된 답변

Mike Danziger
Mike Danziger 2021년 7월 23일
편집: Mike Danziger 2021년 7월 23일
Hi Camilo,
It looks like you are trying to add two plots and a data table to a figure. The problem with your code is that by default your subplots are being placed into a figure, but uitable is only compatible with uifigure. It is possible to place subplots into a uifigure, but it takes a bit more work, and you will have to use a uipanel. Please see the documentation here:
Here is a simplified example that demonstrates what I think you are trying to achieve:
% create a uifigure with desired dimensions
f = uifigure;
f.Position = [1000, 1000, 1200, 800];
% create a uipanel to hold your subplots
panel = uipanel(f);
panel.Position = [0,400,1200,400];
panel.AutoResizeChildren = 'off';
% create subplots parented to the uipanel
ax1 = subplot(1,2,1, 'Parent', panel);
ax2 = subplot(1,2,2, 'Parent', panel);
plot(ax1, 1:10);
plot(ax2, 1:10);
% create a uitable and add it to the uifigure
vars = {'Age','Systolic','Diastolic','Smoker'};
t = t(1:15,vars);
ui_table = uitable(f, 'Data', t);
ui_table.Position = [10, 10, 1180, 380];
Hope this helps!
-Mike

댓글 수: 3

Thank you Mike I will try it the way you suggest. However I try to use your code and I got an error in variable t. I changed to t = table(1:15, vars); and I don't get the error but I don't get a figure or anything...
Got it! Even though the code you posted did not work for me your explantion was very helpful!
I was able to do it:
Thank you Mike!
% create a uifigure with desired dimensions
fig = uifigure;
fig.Position = [80, 80, 900, 600];
% % create a uipanel to hold your subplots
panel = uipanel(fig,'Position',[320 20 570 300]);
panel.AutoResizeChildren = 'off';
% create subplots parented to the uipanel
subplot(1,2,1, 'Parent', panel);
plot(panel, xplot_balance,yplot_balance, '.-')
subplot(1,2,2, 'Parent', panel);
plot(panel, xplot_r,yplot_r, '.-')
% create a uitable and add it to the uifigure
uitable(fig,'Data',Tablecalc, 'Position', [20 400 400 150]);
Hi Camilo,
Apologies, a line got lost at the top of the script when I pasted the code. This just loads some sample data for the table:
t = readtable('patients.xls');
Glad it helped, though!
Cheers,
-Mike

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2021년 7월 27일
Camilo, in general you don't need all those table2array calls. Just do this:
plot(Tablecalc.NameOfYour6thVar,Tablecalc.NameOfYour8thVar, '.-')
If you really, really have a need to pull variables out of a table, do this:
yplot_balance = Tablecalc.NameOfYour6thVar
But chances are you don't need to do that.

댓글 수: 1

Thank you Peter! I am still learning Matlab so it is very useful your suggestion!
CA

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2021년 7월 21일

댓글:

2021년 7월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by