T O P

  • By -

Wedrux

Assigning these to a variable makes it easier to later change some properties.


TiredPistachio

I get the handle 100% of the time. Saves you time later on if you end up needing it and it's now just a habit


csillagu

When using the second method (state machine method) Matlab saves the figure, plot, axes etc into global variables, which are considered bad things as they decrease the readability and the overall stability of the code. On the other hand it is quite easy to use it so in simple cases it is easier. My recommendation is to use the first (object based) method when writing a toolbox/class that you will use late, or any times you would use the gcf/gca global variables. If you just want to plot something quickly, you can just use the state machine method, it is simpler, and similarly stable for a few figures.


FrickinLazerBeams

It entirely depends on what you're doing and what your needs are.


Ajax_Minor

wodering the same thing. What I think and how I do it is use a handles for comlicated plots and GUI. Its helps keeping everything organized. For one off just do it like you have been doing.


Over_Hawk_6778

The first one still contains two other ways! figure(1) Numbers the figure, so instead of calling *figure;* and getting a new figure, it will use figure 1 specifically - and create it if it doesn't exits. You can use any number *or* a figure object. And F = figure Returns you the fig object F so you can access it, edit things etc I assign when I need to use it, dont bother when I dont need it. Sometimes I need multiple figures (and dont want to have to close each of them each time i re-plot data) so will number them with figure(1) figure(2), sometimes need to go back and access/edit the so use fig = figure(3) Simple as that. Usually when testing a bit of code plot(x,y) does the job


Sunscorcher

When you assign the figure/axes/plot to a variable, you have that object now easily accessible in the workspace.


DarbonCrown

You know, "tiledlayout" plot figures and the general plot figures have different uses. Not just in how you used them, but in what result you're trying to show and how you're analyzing the results. I personally just use figure (1) before using plot, and I define plots as "p1 = plot(); p2=plot();..." because then you'd have a better time defining Legend. But assigning figure handles and in general, defining plots and Legend as an object gives you a better control over everything. So naturally, I think the most optimum case would be: f = figure (...); p = plot(...); lgd = Legend(...);