2D plot of particles in contact

2 次查看(过去 30 天)
Lorin Bosoc
Lorin Bosoc 2016-3-4
I have a .txt document with 3 columns that represent the x-coord, y-coord and radii of multiple particles in contact (each particle has a different radius). I am trying to plot them in x-y with their radii, however, when I stretch my figure the radii stay small... I want the radii to change in scale with the scale of the x-y axis. I used the following code to plot the particles and you can also see in the figures attached what I am talking about (which is basically what I don't want).
Can anyone help me please?
clc;
clear all;
%%Data reading from file
%Indicate file + path to file if needed (in base_filename)
base_filename = 'depositiontxt';
%Indicate input file format
file_format = 'txt';
filename = strcat(base_filename,'.',file_format);
%The function creates a structure with the data read from the file. The
%standard format is such:
% Line 1: Variable names separated by 'tab'
% Lines 2-onwards: Values for the variables
% The structure then contains the data as follows:
% structure_name.variable_name_1 = column 1 of the file etc.
C = tdfread(filename,'\t');
% X-coordinates are rounded to the nearest milimetre
x = C.x;
y = C.y;
r = C.r;
%%Plotting
%This controls the size of the points printed (in pixels so quite small)
%Sets the colour of the points and 'fill' used later tells the points to
%be filled
colour = 'blue';
C.a = pi * C.r.^2
%This is the plotting function, you can define the attributes here
scatter(C.x,C.y,C.a*10,colour,'fill'), xlabel('x [mm]'),ylabel('y [mm]'),title('Particle locations');
saveas(gcf,'Figure.png');

回答(1 个)

Image Analyst
Image Analyst 2016-3-4
You can either create an image via the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F
Or you can pass in the sizes to scatter() and plot again once the resizing is done.
  3 个评论
Image Analyst
Image Analyst 2016-3-6
If r are the radii of the circles in mm, then you need to convert that into some size in pixels, like in the range of 3 - 15 or whatever. So figure out the scaling factor to do that, then
% Convert from mm to pixels
scaledSizes = r * scaleFactor;
% Replot with different size markers:
scatter(x, y, scaledSizes);
Lorin Bosoc
Lorin Bosoc 2016-3-7
That's what the code already does, only that the scaled factor is applied directly in the scatter function.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by