Borrar filtros
Borrar filtros

Is there a way of using uitab for Live Script

2 visualizaciones (últimos 30 días)
Matt
Matt el 19 de Dic. de 2023
Comentada: Sudarsanan A K el 20 de Dic. de 2023
Hello, I was wondering if theres a way of producing plots produced in Live Stript within there own window, i.e using uitab?

Respuesta aceptada

Sudarsanan A K
Sudarsanan A K el 19 de Dic. de 2023
Hi Matt,
Yes, it is possible to produce plots in MATLAB Live Scripts within their own window using "uitab".
Here's an example code snippet that demonstrates how to achieve this:
% Create a figure
fig = figure('Name', 'Tabbed Plots', 'Position', [100, 100, 800, 600]);
% Create a tab group
tabGroup = uitabgroup(fig);
% Create tabs
tab1 = uitab(tabGroup, 'Title', 'Sine Wave');
tab2 = uitab(tabGroup, 'Title', 'Cosine Wave');
% Switch to tab 1 and create a plot
axes('Parent', tab1);
x = linspace(0, 2*pi, 100);
plot(x, sin(x), '-o', 'Color', [0.5, 0.2, 0.8], 'MarkerFaceColor', [0.5, 0.2, 0.8]);
title('Sine Wave');
xlabel('Time');
ylabel('Amplitude');
grid on
% Switch to tab 2 and create another plot
axes('Parent', tab2);
plot(x, cos(x), '-*', 'LineWidth', 2, 'Color', [0.2, 0.7, 0.3], 'MarkerFaceColor', [0.2, 0.7, 0.3]);
title('Cosine Wave');
xlabel('Time');
ylabel('Amplitude');
grid on
For further information regarding the "uitab" and "uitabgroup" functions and its use-cases, you can refer to the following MathWorks documentation:
I hope this answers your query!
  2 comentarios
Matt
Matt el 19 de Dic. de 2023
What if you wanted to plot 2 graphs on the same tab i.e using tiledlayout? Thanks
Sudarsanan A K
Sudarsanan A K el 20 de Dic. de 2023
Hi. If you want to plot multiple graphs on the same tab with any specified layout, you can achive that by using either "tiledlayout" or "subplot" as demostrated below.
Using "tiledlayout":
% Create a figure
fig = uifigure('Name', 'Single Tab Tiled Plots');
% Create a tab group
tabGroup = uitabgroup(fig);
% Create a single tab
tab = uitab(tabGroup, 'Title', 'Combined Plots');
% Create a tiled layout within the tab
tLayout = tiledlayout(tab, 2, 1, 'TileSpacing', 'compact', 'Padding', 'compact');
% Plot the sine wave in the first tile
ax1 = nexttile(tLayout);
x = linspace(0, 2*pi, 100);
plot(ax1, x, sin(x), '-o', 'Color', [0.5, 0.2, 0.8]);
title(ax1, 'Sine Wave');
xlabel(ax1, 'Time');
ylabel(ax1, 'Amplitude');
grid(ax1, 'on');
% Plot the cosine wave in the second tile
ax2 = nexttile(tLayout);
plot(ax2, x, cos(x), '-*', 'LineWidth', 2, 'Color', [0.2, 0.7, 0.3]);
title(ax2, 'Cosine Wave');
xlabel(ax2, 'Time');
ylabel(ax2, 'Amplitude');
grid(ax2, 'on');
% Get the figure's current position and size
figPosition = get(fig, 'Position');
% Set the tab group to fill the entire figure
set(tabGroup, 'Position', [0 0 figPosition(3) figPosition(4)]);
Using "subplot":
% Create a figure
fig = figure('Name', 'Tiled Plots', 'Position', [100, 100, 800, 600]);
% Create a tab group
tabGroup = uitabgroup(fig);
% Create a tab
tab = uitab(tabGroup, 'Title', 'Tiled Plots');
% Create subplots in the tab
subplot(2, 1, 1, 'Parent', tab);
x = linspace(0, 2*pi, 100);
plot(x, sin(x), '-o', 'Color', [0.5, 0.2, 0.8]);
title('Sine Wave');
xlabel('Time');
ylabel('Amplitude');
grid on
subplot(2, 1, 2, 'Parent', tab);
plot(x, cos(x), '-*', 'LineWidth', 2, 'Color', [0.2, 0.7, 0.3]);
title('Cosine Wave');
xlabel('Time');
ylabel('Amplitude');
grid on
For further details of these functions, you can refer to the following MathWorks documentations:
I hope this helps!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by