Input argument in a function as a string?

8 次查看(过去 30 天)
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!

采纳的回答

Star Strider
Star Strider 2020-3-11
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by