how add intensity/frequency to the scatter plot

조회 수: 1 (최근 30일)
didi
didi 2018년 3월 6일
댓글: Pawel Jastrzebski 2018년 3월 7일
Hi, I would like to scatter plot these two vectors: X=[0 0 1 2 0 1 1 0]; Y=[1 1 1 1 2 0 0 2]; and had the frequency of occurrence in the color or in the size of the points, something like the attached pic

채택된 답변

Pawel Jastrzebski
Pawel Jastrzebski 2018년 3월 6일
편집: Pawel Jastrzebski 2018년 3월 6일
Consider the code below but also check the documentation for:
X=[0 0 1 2 0 1 1 0];
Y=[1 1 1 1 2 0 0 2];
% find the freqency vector
minVal = min(Y)
maxVal = max(Y)
vectorOfvalues = minVal:maxVal
howMany = Y'==vectorOfvalues
howManySum = sum(howMany);
% this line nicely show how the occurance of a value
% 1st row: value
% 2nd row: occurance
howManySum = [vectorOfvalues; howManySum]
% pre-allocation
occurence = zeros(1,length(Y));
for i=1:length(howManySum)
occurence(Y==howManySum(1,i)) = howManySum(2,i);
end
Y
occurence
% I've added the factor of 50 for the occurance
% so the diffrence between the dot sizes is visible
figure
scatter(X,Y,50*occurence)
  댓글 수: 6
didi
didi 2018년 3월 7일
R2015a..indeed maybe it can be related to the version
Pawel Jastrzebski
Pawel Jastrzebski 2018년 3월 7일
Must be. The code:
howMany = Y'==vectorOfvalues
uses so called implicit expansion which was introduced in version R2016B.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by