0

I have an assignment on MATLAB and have this problem where I have an array: plot_handles = [] and should store different plot handles there.

A main function called 'mainMeny' creates this plot_handles = [] then calls another function plot_handles = createPlot(plot_handles)

And I am to create this createPlot function.

This createPlot function is supposed to ask the user for some mathematical function f(x) and create a plot. The handle for this created plot is to be stored in plot_handles and returned to mainMeny and thus update the plot_handles = [] array to the array that now contains a plot handle. This array should thus contain several plot handles.

the mainMeny function can also call other functions that can change the title of the figure, the width of lines etc, and should be able to choose which plot (each plot plotted on different figures) that we want to change etc.

I just dont seem to be able to store plot handles in an array. Intuitively, I do it like this:

plot_handles(index) = plot(x,y) % or something like that.

But that only makes plot_handles contain some number in that index.

augusti
  • 401
  • 3
  • 6
  • 16
  • In your `createPlot`, how is the handle obtained? `handle = figure();` or something similar? – Nemesis Mar 04 '16 at 09:11
  • well, I create a figure() simply like that. But then I create the handle like this: h = plot(eval(answer{1})). – augusti Mar 04 '16 at 09:14
  • Actually, this is correct. A handle is only a number. What are you going to do with the handle? – Nemesis Mar 04 '16 at 09:18
  • In the mainMeny function, a switch case thing is called which is in a while loop. The while loop opens a meny and you can choose e.g. (1) Create a Plot. So it calls the createPlot function and allows for input of a function f(x). This is plotted and the handle is stored in plot_handles and returned to mainMeny. And so it continues. plot_handles should contain plot handles and users can access these plot handles to make changes to the plots that are ploted in different figures. Many thanx for your response. – augusti Mar 04 '16 at 09:36
  • Yes, this was correct. Of course. It seemed that only some random number was storred in the array. So h = plot(x,y) followed by plot_handles(1) = h solves it. It can then be called with get(plot_handles(1)). Solved. Thanx. – augusti Mar 04 '16 at 10:04

0 Answers0