str and int scatterplot?

조회 수: 6 (최근 30일)
Sumner
Sumner 2013년 8월 23일
Hi! I just started a mathematical modeling course and was instructed to form a scatterplot. While doing two vectors and plotting them is easy, I found that adding data labels was somewhat more challenging with the cellstr function. I was curious though, how one would go about making a scatter plot of three variables, one of which is str and goes on the x axis (such as species) the other two being int (such as height and weight). Any guidance would be greatly appreciated. I have no coding experience so please go easy on me!

답변 (1개)

Walter Roberson
Walter Roberson 2013년 8월 23일
You appear to have three independent variables: (1) species number; (2) height; and (3) weight. In order to form a scatter plot of that, you would need to use scatter3()
Assuming that the labels are in the cell string "str",
nvals = length(height);
scatter3(1:nvals, height(:), weight(:));
set(gca, 'XTick', 1:nvals, 'XTickLabel', str);
Perhaps you would prefer to have a two-dimensional scatter plot in which each point was labeled with its appropriate string? If so, then
scatter(height(:), weight(:));
text(height(:), weight(:), str);
  댓글 수: 2
Sumner
Sumner 2013년 8월 23일
Yeah I am really sorry, but that doesn't explain or make any sense to me. I am 100% beginner :/
I am looking for a two-dimensional scatter plot where the two int variables are on the y axis and the str variable is on the x. I really appreciate your assistance though!
Walter Roberson
Walter Roberson 2013년 8월 23일
scatter(height(:))
hold on
scatter(weight(:))
set(gca, 'XTick', 1:length(height), 'XTickLabel', str);

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

카테고리

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