How to replace a pointer or marker with an object for tracing the desired path?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 ?
採用された回答
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 件のコメント
here it only jumps to the coordinates, without tracing the entire path.i i also want to fill the blue colour within the object.
Then you need to give additional coordinates to fill in the "in between" points. Instead of just 4 coordinates, use like a hundred or something. i trust you can do that if you use linspace() - look it up in the help if you're not familiar with it. It's easy to use so I'm sure you can do it.
You can use the 'FaceColor, 'b' to get filled blue.
It is not possible for the code to trace the entire path. There is an infinity of points between any two coordinates, but the coordinates of any point that MATLAB can draw only has finite resolution.
MATLAB only renders at single precision. If we consider moving from (10,10) to (5,10), that would require moving from single(10.0) to single(5.0). I calculate that would require 8388608 steps in single precision. At 100 frames per second, that would require 23 hours 18 minutes. But first it would have had to move from (10,0) to (10,10), which I calculate would take over 34 years at 100 frames per second.
You may wish to reconsider not allowing the plotting to jump between coordinates.
tried, suggest corrections as the code doesnot yield the required output
x8d=linspace(150,98,180)
y8d=linspace(69,69,180)
%r6=24
xc8 = 75;
yc8 = 69;
r1=23
theta11 = linspace(0,-pi,180);
x8c = r1*cos(theta11) + xc8;
y8c = r1*sin(theta11) + yc8;
x8b=linspace(52,0,180)
y8b=linspace(69,69,180)
x888=[ x8d x8c x8b];
y888=[ y8d y8c y8b];
axis([0 50 0 50])
for k1 = 1:540
r=rectangle('Position', [x888(k1) y888(k1) 0.5 1], 'FaceColor',[0 0 1])
set(r, 'Position',[x888(k1) y888(k1) 0.5 1]);
drawnow
end
axis([0 150 0 70])
and remember to add a semi-colon at the end of the "rectangle" call. Also you do not need the set() call.
Thank you so much for your guidance
why is this error shown whenever i run the code "While setting property 'Position' of class 'Rectangle': Value must be numeric"
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!
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)
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Graphics Object Properties についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
