How do I change the Contourf scale

I am importing particle tracking data as x-y coordinates into MATLAB and plotting them on a contour plot (using contourf). I believe I just need to change the scale, but cannot find the correct one to set it to.
** EDIT I just realised I am not trying to change the scale but rather the size of the 'bin' - from only 1 coordinate to a 5x5m area to collect the particles in.
My current contours look like this:
Image 1 above with 100k x-y points
Image 2 above uses only 100 points.
I need the contour to look more like the one below so that you can easily see the density over the domain. I have tried changing the scales but just can't seeem to get it to work.
Image 3 above - what ideally mine should look like.
Below is my code, where x and y are the list of coordinates. I know it's probably really simple but any help would be appreciated :)
x = store(:,1);
y = store(:,2);
store(1,:)=[];
d2=ceil(min(store(:,2)));d1=ceil(min(store(:,1)));
u2=ceil(max(store(:,2)));u1=ceil(max(store(:,1)));
matr=zeros(u2-d2+1,u1-d1+1);
for i=1:length(store)
matr(ceil(store(i,2))-d2+1,ceil(store(i,1))-d1+1)= matr(ceil(store(i,2))-d2+1,ceil(store(i,1))-d1+1)+1;
end
figure(1)
f = figure(1);
axes1 = axes('Parent',f);
hold(axes1,'on');
[C,h] = contourf(d1:ceil(max(store(:,1))),(d2:ceil(max(store(:,2))))',(log(matr+1)));
h.LineWidth = 0.0001;
box(axes1,'on');
c = colorbar(axes1);
xlabel('Y-direction [m]')
ylabel('X-direction [m]')

5 Comments

store is just all my x-y coordinates
Apparently you code provides the correct data to contourf.
The contourf function will likely bin them appropriately. You simply need to tell it what you want it to do, with respect to your data.
I outlined two possiblle methods (if I understand your problem correctly) that could work. You have not yet commented on whether they do, and if they do not, what they do that you do not want them to do, or what they do not do that you would like them to do.
Also, without your data, I cannot experiment myself to see what possibilities (if any) might be appropriate.
Appologies. The data file is .mpg0007 which is not supported to upload - I could email it with the .m file?
I appreciate your previous suggestions - I had realised that it was not the scale that I was trying to change but rather the capture area - I edited this in the post but not as a direct reply (first forum post sorry aha).
I should also say that this code was not written by me entirely so I do not fully understand it enough to change the capture area or bin area to contain more than one coordinate. Logically I think a larger capture area (instead of counting particles at one coordinate counting them in an area of 5x5m or larger instead and plotting this in the contour) would solve the problem but I could be wrong.
The contourf function can ‘bin’ the particles with specific contour levels, if the data are what I believe them to be.
Rather than sending the file itself, one option woulkd be to save the specific data you loaded into your script from it (and later use in the contourf call) as a .mat file, and then upload the .mat file.
There is nothing more I can do at this point without it.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 14 Feb 2021
The contour functions all allow the ability to define the number of contours as well as specific levels. In the contourf documentation see Contours at Ten Levels and Contours at Specific Levels with Labels (the labels are optional).

Categories

Tags

Asked:

on 14 Feb 2021

Commented:

on 15 Feb 2021

Community Treasure Hunt

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

Start Hunting!