필터 지우기
필터 지우기

Is there a way of using uitab for Live Script

조회 수: 1 (최근 30일)
Matt
Matt 2023년 12월 19일
댓글: Sudarsanan A K 2023년 12월 20일
Hello, I was wondering if theres a way of producing plots produced in Live Stript within there own window, i.e using uitab?

채택된 답변

Sudarsanan A K
Sudarsanan A K 2023년 12월 19일
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
Matt
Matt 2023년 12월 19일
What if you wanted to plot 2 graphs on the same tab i.e using tiledlayout? Thanks
Sudarsanan A K
Sudarsanan A K 2023년 12월 20일
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!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by