필터 지우기
필터 지우기

How to plot string on X-axes and number in Y-axes in figure?

조회 수: 255 (최근 30일)
Tania Islam
Tania Islam 2021년 1월 8일
댓글: Muhammed Turhan ÇAKIR 2022년 10월 4일
Hello,
I want plot my RMSE data value on the y-axes and the string the value on the x-axes for my research work paper.
I need to set legend also. I tried following code but its not working
Following is the sample code
x_axes=['Case-1','Case-2','Case-3','Case-4']
Y_axes=[4,5,6,7]
figure('name','sample','PaperSize',[3.3 2.71],'NumberTitle','off');
plot(Y_axes)
set(gca,'xticklabel',x_axes.')

채택된 답변

Steven Lord
Steven Lord 2021년 1월 8일
This doesn't do what you think it does.
x_axes=['Case-1','Case-2','Case-3','Case-4']
x_axes = 'Case-1Case-2Case-3Case-4'
Instead use a string array or a cell array each element of which is a char vector.
x_axes1=["Case-1","Case-2","Case-3","Case-4"]
x_axes1 = 1×4 string array
"Case-1" "Case-2" "Case-3" "Case-4"
x_axes2={'Case-1','Case-2','Case-3','Case-4'}
x_axes2 = 1x4 cell array
{'Case-1'} {'Case-2'} {'Case-3'} {'Case-4'}
But plot is not defined for either string or cellstr variables. You could instead convert that text data to categorical and make a categorical plot.
C = categorical(x_axes1)
C = 1×4 categorical array
Case-1 Case-2 Case-3 Case-4
plot(C, (1:4).^2, 'ko-')
  댓글 수: 4
Tania Islam
Tania Islam 2021년 1월 8일
Thank you so much. It works with my code :)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by