Input argument in a function as a string?

9 visualizaciones (últimos 30 días)
Jenniluyn Nguyen
Jenniluyn Nguyen el 11 de Mzo. de 2020
Respondida: Star Strider el 11 de Mzo. de 2020
Hello,
I'm working on a function that's supposed to visualize large sets of data. This is what I have so far -
function visualize(data,xlabels,ylabels,titles,xticks)
hold on
for i = 1:length(data)
graph = plot(data(i,:));
pause(0.1);
end
graph.xlabel = xlabels;
graph.ylabel = ylabels;
graph.title = titles;
set(gca, 'XTickLabel', {xticks});
hold off
I realized that I'm not sure how to make it so the xlabel, ylabel etc. are assigned to the xlabels, ylabels input argument, which is supposed to be a string. Is there an explicit way to do this?
I'm also trying to figure out how to make xlabels, ylabels, titles, and ticks optional (so that there's a default option whenever it's not explicitly put.)
Thanks in advance!

Respuesta aceptada

Star Strider
Star Strider el 11 de Mzo. de 2020
It’s a bit more involved than that.
The axis labels and the title are Axes Properties, not Line properties, so:
ax.XLabel.String = xlabels;
ax.YLabel.String = ylabels;
ax.Title.String = titles;
would work.
I’m not certain what you’re doing with respect to the loop. If you have different axis labels and titles for each plot, you‘ll need to include them in the loop and assign them each time, possibly subscripting them if there are different ones for each plot. Otherwise, they would only be assigned to the last plot.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by