"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
@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 )?
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()
Thanks again.
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)
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
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? ..)
Thanks for the approach.
Forgot, sorry.
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
