"Index exceeds matrix dimensions" Error. solution please.
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
x1=60;x2=40; y1=40; y2=60;
d = sqrt((x2-x1)^2+(y2-y1)^2);
a = atan2(-(x2-x1),(y2-y1));
b = asin(d/2/r);
c = linspace(a-b,a+b);
e = sqrt(r^2-d^2/4);
x = (x1+x2)/2-e*cos(a)+r*cos(c);
y = (y1+y2)/2-e*sin(a)+r*sin(c);
axis([0 150 0 150])
hold on
plot(x,y,'r');
axis([0 150 0 150])
h1 = plot(x(1),y(1),'bs','MarkerSize',7,'MarkerFaceColor','r');
for n = 1:numel(t)
set(h1, 'XData', x(n), 'YData', y(n)); %HERE
drawnow %// refresh figure
end
The error is displayed in the highlighted line.
suggest solution. (what should be the value of t here)
Here, the program runs even without specifying the value of t. how is it possible?
Can the speed of the pointer be controlled (in terms of frequency/velocity) by the user given input (from dialog box)?
1 件のコメント
Jan
2016 年 11 月 4 日
@h b: Please format your code using the "{} code" button. It is easier to help you, when the code is readable.
採用された回答
Walter Roberson
2016 年 11 月 4 日
You have an old t variable sitting around or passed in,and it is longer than your x is.
14 件のコメント
is it also possible to increase the matrix dimension such that it matches my index value (i.e. t )?
h b
2016 年 11 月 7 日
can i resize my matrix size from 1*100 to 1*180 for an index value of 180.
Yes, you can extend x and y:
nt = numel(t);
x(end+1:nt) = nan;
y(end+1:nt) = nan;
but wouldn't it be much easier to just use a variable that has some relevance to the code you presented?
for n = 1:numel(x)
h b
2016 年 11 月 7 日
編集済み: Walter Roberson
2016 年 11 月 7 日
thanks. yes i had got the solution.
Could you rectify the error in the below mentioned code as the pointer stops without trailing the entire path.
t=linspace(0,40,180)
x3=linspace(54,54,180);% left
y=linspace(0,40,180);
a1=54;a2=44; b1=40; b2=60;
d = sqrt((a2-a1)^2+(b2-b1)^2); % Distance between points
a = atan2(-(a2-a1),(b2-b1)); % Perpendicular bisector angle
b = asin(d/2/r); % Half arc angle
c = linspace(a-b,a+b); % Arc angle range
e = sqrt(r^2-d^2/4); % Distance, center to midpoint
q = (a1+a2)/2-e*cos(a)+r*cos(c); % Cartesian coords. of arc
z = (b1+b2)/2-e*sin(a)+r*sin(c);
nt = numel(t);
q(end+1:nt) = nan;
z(end+1:nt) = nan;
xa=linspace(44,0,180);
ya=linspace(60,60,180);
x111=[ x3 q xa ]
y111=[ y z ya ]
axis([0 150 0 150]);
hold on;
h1 = plot(x111(1),y111(1),'bs','MarkerSize',7,'MarkerFaceColor','r'); %// plot initial position of object 1
for n = 1:numel(t)
set(h1, 'XData', x111(n), 'YData', y111(n)); %// update position of object 2
drawnow %// refresh figure
end
Do not extend q and z with nan. Instead, you should be using
for n = 1:numel(x111)
You do not not ask for any trailing at all. If you want trailing then
for n = 1:numel(t)
set(h1, 'XData', x111(1:n), 'YData', y111(1:n)); %// update position of object 2
drawnow %// refresh figure
end
Or better yet, look at animatedline()
h b
2016 年 11 月 7 日
Thanks again.
h b
2016 年 11 月 7 日
any way to control the speed of the pointer as per the user input?
fps = input('How many frames per second? ')
delay = 1/fps;
and replace
drawnow
with
pause(delay)
h b
2016 年 11 月 11 日
Thank you. i wish to user input speed in terms of velocity(distance/time) from excel. in order to achieve the same, is it possible to divide my matlab output figure into cells of desired dimension
Walter Roberson
2016 年 11 月 11 日
Yes, it is possible to divide your output figure into cells of desired dimension. It is also a lot of work.
Easier is to calibrate your output rate to the virtual distance to be traveled.
See attached.
The first parameter to the function is r, the radius, which you never defined in your posting so I decided it must be something you wanted to adjust.
The second parameter is v, the velocity. The total distance to be traveled is about 120, so approximately 120/v will give the number of seconds the output will take to plot.
An easier version of the code would be to say that the distance between adjacent points is "close enough" to equal, and so to divide the calculated time by the number of points and advance equally. It turns out that the overhead of doing that gets fairly high for higher velocities (shorter wait times.) And because you are traveling on a curve, you should not really be calling the distances to be equal.
The version of the code I attach calculates the distances between adjacent points by Euclidean formula, totals the distances, uses the velocity to calculate times. Then, to allow the plot to proceed at constant linear velocity, it divides the time up into a number of chunks and figures out where on the curve (which sample) one would be at after that time. Then it plots with the trail increasing one chunk at a time.
("The version of the code I attach..." Have u provided any attached file for reference? ..)
h b
2016 年 11 月 11 日
Thanks for the approach.
Walter Roberson
2016 年 11 月 11 日
Forgot, sorry.
h b
2016 年 11 月 11 日
Thank you so much.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Graphics Performance についてさらに検索
タグ
参考
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)
