creating circles for multiple points with viscircle

18 views (last 30 days)
I have some time points in variable t and some position values in variable z, and want to make circles of radius 0.5 at those points using viscircles. How would I set that up?

Answers (3)

Walter Roberson
Walter Roberson on 27 Jan 2020
viscircles([t(:), z(:)], 0.5)

Image Analyst
Image Analyst on 27 Jan 2020
viscircles() is meant for images. I'm not sure that you have an image. You seem to have a time signal and a z signal. You just want plot()
t = 1 : 20;
z = rand(size(t));
plot(t, z, 'bo-', 'MarkerSize', 20, 'LineWidth', 1);
grid on;
xlabel('Time', 'FontSize', 15);
ylabel('Z', 'FontSize', 15);
title('Z vs. Time', 'FontSize', 15);
Vary the marker size until you get the look you desire.
0000 Screenshot.png
  3 Comments
Walter Roberson
Walter Roberson on 27 Jan 2020
?? viscircles is not specifically meant for images ??
Image Analyst
Image Analyst on 27 Jan 2020
If it does what you want then that's fine. viscircles() is part of the Image Processing Toolbox, though it appears it can also be used on an axes without an image in it. However the radius of 0.5 can apply to the z direction only. It will still be a circle, but the width in the time direction won't be a distance, it will be a time.

Sign in to comment.


Adam Danz
Adam Danz on 27 Jan 2020
Edited: Adam Danz on 27 Jan 2020
To plot a set of circles defined by their center points and a radius, you can use the the rectangel function with 100% curvature.
Here's a demo.
% Define (x,y) centers
circleCenters = [
1.0 2.5
1.5 3.0
2.1 1.1
3.0 2.5];
% Define radius
r = 0.5;
% create rounded rectangles (ie, circles) for
% each center point. The rectangle is defined
% by its lower, left corner so the circle
% centers need shifted have 1/2 the radius.
lowerLeft = circleCenters - r/2;
% plot the rectangles
clf()
cla()
hold on % important
arrayfun(@(i)rectangle('Position',[lowerLeft(i,:),r,r],...
'Curvature',[1,1]), 1:size(lowerLeft,1));
axis equal % so circles appear circular
% add circle centers
plot(circleCenters(:,1),circleCenters(:,2),'rx')
If you'd rather use viscircles on those data,
% or this method
cla()
viscircles(circleCenters,repmat(r,size(circleCenters,1),1));
axis equal

Tags

Community Treasure Hunt

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

Start Hunting!