MATLAB: Scatter plot with different radius for different range of values

bubble plotfor loopif statementscatterscatter plot

*I have three column vectors , Latitude ,longitude,magnitude of earthquake (338×1),
*so I need to make a scatter plot (X axis :longitude,Y axis :latitude),
  • But the radius of the scatter should be same for particular range of magnitude,like mag<3,3=<mag<4,4<=mag<5….. 9=<mag<10.
So I should read the magnitude first and plot the scatter for corresponding latitude and longitude with radius according to the magnitude range
can anyone help me with this?

Best Answer

I know it's not as elegant as we hope, but one way is to create a new variable that represents the radius and then use scatter function. logical indexing could perform better than using for-loop.
The following is one example. Hope it helps.
[x,y] = meshgrid(1:10,1:10);
% Magnitude with random number ranging from 0 to 10.
mag = rand(1,100)*10;
idx1 = mag < 3;
idx2 = (3 <= mag) & (mag < 5);
idx3 = (5 <= mag) & (mag < 8);
idx4 = 8 <= mag;
magSize = zeros(size(mag));
magSize(idx1) = 1;
magSize(idx2) = 9;
magSize(idx3) = 25;
magSize(idx4) = 49;
scatter(x(:),y(:),magSize);