Borrar filtros
Borrar filtros

How to repeat the use of a function?

2 visualizaciones (últimos 30 días)
Farid
Farid el 7 de Sept. de 2014
Editada: Rick Rosson el 7 de Sept. de 2014
I am trying to run the same function multiple times within a script. The function plots a figure after I input the variables. I am trying to superimpose the multiple figures into one graph while using the same function. I used the "hold on" command after each plot, but I only get the graph of the first inputted variables. How do I reiterate the use of the function?

Respuestas (1)

Rick Rosson
Rick Rosson el 7 de Sept. de 2014
You need to create the figure and axes in the script before you call the function that does the plotting. You should pass the axes handle as an input to your potting function.
Your script should look something like the following:
fig = figure;
ax = axes;
hold on
myplotfunc(ax,x,y,z);
myplotfunc(ax,u,v,w);
...
Inside your plotting function, make sure you pass the axes handle as the first argument to any plot command that you call.
HTH.
  3 comentarios
Rick Rosson
Rick Rosson el 7 de Sept. de 2014
Please format your code so that it is easy for others to read.
Rick Rosson
Rick Rosson el 7 de Sept. de 2014
Editada: Rick Rosson el 7 de Sept. de 2014
Please review the answer that I provided and try implementing it. It will work.
Hint:
P = fill(x,y,color,'parent',ax);

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by