How can I create a plot with column headings along the X-axis?

조회 수: 7 (최근 30일)
Deepa T
Deepa T 2017년 7월 5일
댓글: Star Strider 2017년 7월 6일
Hi I need to plot a matrix such that every column heading is listed along the x-axis and every cell in that column is plotted along the Y-axis? I have attached a picture of the same. I am a newbie to MATLAB. Could someone please help? Thanks in advance Deepa

채택된 답변

Star Strider
Star Strider 2017년 7월 5일
Try this:
M = randi(9, 3); % Create Matrix
x = 1:size(M,2); % Column numbers
labelstr = sprintf('Column %d\n', x); % Create Labels
labelcel = regexp(labelstr, '\n', 'split'); % Split & Create Cell Array
figure(1)
plot(x, M', '.b', 'MarkerSize',20)
set(gca, 'XTickLabel',[])
set(gca, 'XTick',x, 'XTickLabel',labelcel(1:end-1), 'XTickLabelRotation',90)
axis([0 4 0 10])
  댓글 수: 4
Deepa T
Deepa T 2017년 7월 6일
Thank you very much. It is working perfectly now.
Star Strider
Star Strider 2017년 7월 6일
As always, my pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by