필터 지우기
필터 지우기

How to use scrollsubplot in a panel in app designer?

조회 수: 4 (최근 30일)
Careniena Opem
Careniena Opem 2022년 9월 2일
댓글: Dolon Mandal 2023년 9월 20일
I have a GUI with two panels. One panel is filled with a number of plots after pushing a button. The number of plots can vary, but when this number increases the plots get very squished together and hard to read. I thought I could work around this using the scrollsubplot() function from file exchange, but each time the button is pressed a separate figure is opened. The plots populate the correct areas in the panel, but the scrollbar is located in this new figure. Here is a portion of my code:
PlotInd = 1;
axBrainStO2 = scrollsubplot(4,1,PlotInd);
axBrainStO2.Parent = app.RightPanel;
plot(axBrainStO2,app.timeNIRS,app.BrainStO2,'m-','LineWidth',1.5)
Is there any way to fix this?
  댓글 수: 4
Careniena Opem
Careniena Opem 2022년 9월 7일
@Bjorn Gustavsson Any other ideas? I'm still pretty stuck...
Dolon Mandal
Dolon Mandal 2023년 9월 20일
Instead of using the scrollsubplot function, you can create a single axes object within your panel and update its position dynamically based on the number of plots. Here's an example of how you can modify your code:
% Assuming you have a GUI with a panel named 'RightPanel'
% Calculate the number of rows and columns based on the number of plots
numPlots = 4; % Replace with your actual number of plots
numRows = ceil(sqrt(numPlots));
numCols = ceil(numPlots / numRows);
% Calculate the position of the axes within the panel
plotInd = 1; % Replace with the appropriate plot index
plotPosition = [mod(plotInd-1, numCols)/numCols, floor((numRows-1-(plotInd-1)/numCols))/numRows, 1/numCols, 1/numRows];
% Create the axes within the panel
axBrainStO2 = axes('Parent', app.RightPanel, 'Position', plotPosition);
% Plot the data on the axes
plot(axBrainStO2, app.timeNIRS, app.BrainStO2, 'm-', 'LineWidth', 1.5);
In this modified code, we calculate the number of rows and columns based on the desired layout of the plots. Then, we calculate the position of each plot within the panel using the plot index and the number of rows and columns. The plotPosition variable represents the position of each plot as a normalized value between 0 and 1.
Next, we create an axes object within the panel using the axes function and set its position using the Position property. The Parent property is set to the RightPanel to ensure that the axes is embedded within the panel.
Finally, we plot the data on the axes using the plot function.
You can repeat this code for each plot, updating the plotInd and plotPosition variables accordingly.
With this approach, all the plots will be contained within a single axes object, and you can control their positions and layout within the panel.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by