Insert two plots and a precreated table in the same figure
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Camilo Acevedo
le 21 Juil 2021
Commenté : Camilo Acevedo
le 27 Juil 2021
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!
0 commentaires
Réponse acceptée
Mike Danziger
le 23 Juil 2021
Modifié(e) : Mike Danziger
le 23 Juil 2021
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 commentaires
Mike Danziger
le 26 Juil 2021
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
Plus de réponses (1)
Peter Perkins
le 27 Juil 2021
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.
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!