How to replace a pointer or marker with an object for tracing the desired path?

1 view (last 30 days)
figure;
hold on
a=plot([10 10 5 5],[0 10 10 15],'r')
xlim([0 20])
ylim([0 20])
I want an object defined as blue rectangle with dimensions 0.5m*1m to trace the path given in the code.
How to do ?

Accepted Answer

Image Analyst
Image Analyst on 23 Jan 2017
Use plot(), rectangle(), and pause(). Try this:
x = [10 10 5 5];
y = [0 10 10 15];
a=plot(x, y, 'r', 'LineWidth', 3)
xlim([0 20])
ylim([0 20])
xticks(0:20);
yticks(0:20);
grid on
hold on;
axis equal
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
yHeight = 0.5;
xWidth = 1;
for k = 1 : length(x)
xBoxLeft = x(k) - xWidth/2;
yBoxBottom = y(k) - yHeight/2;
hRect = rectangle('Position', [xBoxLeft, yBoxBottom, xWidth, yHeight], 'LineWidth', 2, 'EdgeColor', 'b');
pause(1);
delete(hRect);
end
  9 Comments
Image Analyst
Image Analyst on 24 Jan 2017
You forgot to include your complete error message, so we can't see what string or other variable you're putting into the array. It must be numbers, not strings, structures, etc. Please show ALL THE RED TEXT not just part of it. You left out the crucial part - your line of code!
h b
h b on 25 Jan 2017
Edited: h b on 25 Jan 2017
the error message :
Error using rectangle While setting property 'Position' of class 'Rectangle': Value must be numeric
Error in pointer14 (line 30) r=rectangle('Position', [x888(k1) y888(k1) 1 3], 'FaceColor','r');
(For the code mentioned in the comments)

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!