How to Stop Matlab from Opening a New Figure in GUI?

In summary, the conversation discusses the use of a GUI to read and plot data from an oscilloscope and the desire to add two vertical lines to mark the beginning and end times of CCE measurement. The code used for this purpose involves checking for the existence of values and plotting them with the vline function, but after a few executions, Matlab opens a new figure without any explanation. The speaker is seeking help in fixing this bug.
  • #1
Jopi
14
0
Hello all,
I've programmed a GUI to read and plot data from oscilloscope. I have a timer function that updates the graph at 1 Hz frequency.
What I want to is to add two vertical lines to the same figure that mark the beginning and end times of CCE measurement. For that purpose, I'm using the vline -function from Mathworks file central. The code that I've tried to plot those lines with looks like this:

Code:
if(isappdata(0,'ccestart') && isappdata(0,'cceend'))
    axes(maingui.mainscreen)
    vline(getappdata(0,'ccestart'),'--k','CCE Start');vline(getappdata(0,'cceend'),'--k','CCE End');
end

Basically it just checks that if there exists values for CCE Start and CCE End, which it then uses as the x coordinates.
The problem is that for about the first five executions of the timer function, it does plot them in the correct figure. But after that, Matlab decides to open a new figure for me. I get no error message, or any reason for that. This is very annoying, and I'd love to know how to fix this bug. Or if it is fixable at all.
 
Physics news on Phys.org
  • #2
Any help would be greatly appreciated. Thank you!</code>The code that I've tried to plot those lines with looks like this:<code>if(isappdata(0,'ccestart') &amp;&amp; isappdata(0,'cceend')) axes(maingui.mainscreen) vline(getappdata(0,'ccestart'),'--k','CCE Start');vline(getappdata(0,'cceend'),'--k','CCE End');end</code>Basically it just checks that if there exists values for CCE Start and CCE End, which it then uses as the x coordinates. The problem is that for about the first five executions of the timer function, it does plot them in the correct figure. But after that, Matlab decides to open a new figure for me. I get no error message, or any reason for that. This is very annoying, and I'd love to know how to fix this bug. Or if it is fixable at all. Any help would be greatly appreciated. Thank you!
 
  • #3


I can see that you have set up a GUI in Matlab to read and plot data from an oscilloscope. It seems like you have successfully implemented a timer function that updates the graph at a frequency of 1 Hz. In order to add two vertical lines to the same figure, you are using the vline-function from Mathworks file central. Your code checks for the existence of values for CCE Start and CCE End, and then uses them as the x coordinates for plotting the lines.

However, you have encountered a problem where after the first five executions of the timer function, Matlab opens a new figure instead of plotting the lines in the correct figure. This can be frustrating and you are looking for a solution to fix this bug.

I would suggest that you carefully check your code and make sure that there are no errors or conflicts that could be causing this issue. You may also want to try debugging your code to see where the problem is occurring. Additionally, you can try reaching out to the Mathworks community or their technical support team for assistance in resolving this issue.

In general, it is important to thoroughly test and debug your code when developing a GUI in Matlab or any other programming language. This will help ensure that your program runs smoothly and without any unexpected errors. I wish you the best of luck in resolving this issue and successfully implementing your GUI.
 

1. How do I plot data into a GUI in Matlab?

To plot data into a GUI in Matlab, you can use the plot function. First, create a figure handle using the figure function, then use the axes function to create an axes object within the figure. Finally, use the plot function to plot your data within the axes object.

2. Can I customize the appearance of my plot in a Matlab GUI?

Yes, you can customize the appearance of your plot in a Matlab GUI by using various formatting functions such as title, xlabel, ylabel, legend, and grid. These functions allow you to add a title and labels to your plot, as well as customize the legend and grid lines.

3. How can I update my plot in real-time in a Matlab GUI?

To update your plot in real-time in a Matlab GUI, you can use the set function within a loop. This function allows you to update the properties of your plot, such as the data points or axes limits, as the loop iterates. You can also use the drawnow function to refresh the plot after each iteration.

4. Is it possible to save my plot from a Matlab GUI?

Yes, you can save your plot from a Matlab GUI by using the saveas function. This function allows you to save your plot as an image file, such as a PNG or JPEG, or as a figure file that can be opened and edited in Matlab.

5. Can I have multiple plots in a single GUI window in Matlab?

Yes, you can have multiple plots in a single GUI window in Matlab by using the subplot function. This function allows you to divide your GUI window into multiple axes objects, each of which can contain a different plot. You can also use the hold function to keep each plot on the same set of axes.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
572
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
939
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
12K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
Back
Top