How to replace a pointer or marker with an object for tracing the desired path?
1 view (last 30 days)
Show older comments
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 ?
0 Comments
Accepted Answer
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
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!
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!