필터 지우기
필터 지우기

Input argument in a function as a string?

조회 수: 8 (최근 30일)
Jenniluyn Nguyen
Jenniluyn Nguyen 2020년 3월 11일
답변: Star Strider 2020년 3월 11일
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