- "uitab": https://mathworks.com/help/matlab/ref/uitab.html
- "uitabgroup": https://mathworks.com/help/matlab/ref/uitabgroup.html
Is there a way of using uitab for Live Script
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Matt
il 19 Dic 2023
Commentato: Sudarsanan A K
il 20 Dic 2023
Hello, I was wondering if theres a way of producing plots produced in Live Stript within there own window, i.e using uitab?
0 Commenti
Risposta accettata
Sudarsanan A K
il 19 Dic 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 Commenti
Sudarsanan A K
il 20 Dic 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:
- "tiledlayout": https://mathworks.com/help/matlab/ref/tiledlayout.html
- "subplot": https://mathworks.com/help/matlab/ref/subplot.html
I hope this helps!
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Axes Appearance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!