필터 지우기
필터 지우기

Scatter Plot with string in x-axis and integer on y-axis

조회 수: 56 (최근 30일)
Mahaveer Uttamchand
Mahaveer Uttamchand 2019년 7월 22일
댓글: TADA 2019년 7월 22일
My data is
samples=["4S1";"4S2";"4S3";"4S4";"4S5"]';
percentage=[0;-11.5000000000000;-2.44000000000000;-8.13000000000000;-2.44000000000000]';
scatter(samples,percentage);
Error Message:
Error using scatter (line 56)
Input arguments must be numeric, datetime, duration or categorical.
Can anyone please help?
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 7월 22일
I tried with the code, no error in my case. But the question is obvious, samples is strings, how you are going to plot with non numeric variables? Are you looking for Bar Plot?
Mahaveer Uttamchand
Mahaveer Uttamchand 2019년 7월 22일
Thank you KALYAN ACHARJYA for your answer, however, please check my answer that I posted recently. Have a good day. Thank you once again :)

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

채택된 답변

Mahaveer Uttamchand
Mahaveer Uttamchand 2019년 7월 22일
I had found myself recently, actually as mentioned in the error, it should be categorical,
Here is the program,
n=["4S1";"4S2";"4S3";"4S4";"4S5"]';
y=[0;-11.5000000000000;-2.44000000000000;-8.13000000000000;-2.44000000000000]';
x=categorical(n);
s=scatter(x,y);
and if you want your graph to look nice, use the following,
s.LineWidth = 0.6;
s.MarkerEdgeColor = 'b';
s.MarkerFaceColor = [0 0.5 0.5];
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 7월 22일
편집: KALYAN ACHARJYA 2019년 7월 22일
Ohh Yes, its Nice, Thank You.
TADA
TADA 2019년 7월 22일
Elegant solution +1 from me

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

추가 답변 (1개)

TADA
TADA 2019년 7월 22일
Maybe bar chart would be better for you, but if you must use scatter plot
scatter(1:5,percentage);
set(gca, 'XTick', 1:5, 'XTickLabel', samples);
  댓글 수: 2
TADA
TADA 2019년 7월 22일
One more thing, when you need to plot something but don't know how, its always a good idea to check the plot gallery
Mahaveer Uttamchand
Mahaveer Uttamchand 2019년 7월 22일
Thank you TADA for your answer, however, please check my answer that I posted recently. Have a good day. Thank you once again :)

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by