How do i fill this cilinder matrix with ones
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I've an matrix of a cilinder but the "inside" isn't completely filled with ones and I need it for further purposes of the function. Does somebody have a way to do this?
if true
height = linspace(8.1280,0,20);
radius = linspace(30,30.5,20);
% Scale factor: number of pixels per mm, chosen gridsize on the base of calculation time
% and accuracy of the graph - VOXELS
factor = 8;
r = radius.*factor;
h = height.*factor;
%%Creation of flattening filter matrix:
% Creating an empty 3D array based on the size of the flattening filter
maxx = round((max(r) + 10)); % Size of the volume (X-direction); maximum value of flattening filter radius is used.
% + 10 is to create more space, to have a volume sure big enough.
maxy = round((max(r) + 10)); % Size of the volume (Y-direction); Idem.
maxz = round((max(h) + 10));
XmatrixFF = (2*maxx)+1; % Volume with variable size. The + 1 statement is for creating a centre point.
YmatrixFF = (2*maxy)+1; % The centre point is de collimator axis. Imagine the square field with a cross in it.
Rmax = ceil(sqrt(maxx.^2 + maxy.^2)); % creation of the radius, Rmax = srqt(x^2 + y^2)
R = (0:Rmax); % R = kolom vector van 0 tot Rmax
H = interp1(r,h,R,'linear'); % Connects the height points linearly, to find the corresponding height of radius ri.
[~,~,z] = meshgrid(1:XmatrixFF,1:YmatrixFF,1:maxz); % creation of a vector x with numbers starting from 1 to the value
% of XmatrixFF with the numbers of rows equal to the difference in
% end and begin value of the y vector.
% And because its a 3D array there are two more of this 2D matrices.
[xi, yi, ~] = meshgrid(-maxx:maxx, -maxy:maxy, 1:maxz); % This meshgrid creates an xi vector starting with the -maxx and going to +maxx
% And also creates an yi vector starting with -maxy and going to +maxy.
% The zi starts again with 1 and goes to maxz.
% [x,y,z] = meshgrid(1:XmatrixFF,1:YmatrixFF,1:maxz);
ri = round(sqrt(xi.^2 + yi.^2)); % The radius depends on the xi and yi from the meshgrid created above
ffilter = z < H(ri+1); % ffilter is the volume when the value of z is smaller than the height that corresponds to (ri+1)
% The +1 is used to avoid the working with a radius of zero
end
Thanks very much in advance
5 commentaires
Réponses (1)
Jan
le 12 Juin 2018
I'd use some simple code like this to create a 3D array with a cylinder filled by ones:
x = -maxx:maxx;
y = (-maxy:maxy).';
circ = (x .^ 2 + y .^ 2 <= R ^ 2); % >= R2016b: Auto-expand
Cyl = rempat(circ, 1, 1, maxz);
It is not clear to me, why your radius is a vector, why you interpolate r and why the two meshgrid commands are needed.
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!