quiver to show the magnitude of velocity

조회 수: 11 (최근 30일)
Changoleon
Changoleon 2016년 11월 25일
편집: Changoleon 2016년 11월 25일
Hi all,
I have the following:
x=1;
y=1;
u=3;
v=4;
w = sqrt(u^2+v^2);
now if I use quiver(x,y,u,v) and click on the arrow by cursor, I will have x and y along with velocities in x and y axis are going to be shown. I want to my cursor to show the magnitude of the velocity which is w. For that I have watched the following video and tried to do the same job.
Following is what I have done:
function moneyplot(x,y,u,v)
fh = figure;
quiver(x,y,u,v,0)
dcm = datacursormode(fh);
datacursormode on
set(dcm, 'updatefcn', @myfunction)
end
function output_txt = myfunction(obj,event_obj,w)
pos = get(event_obj,'Position');
output_txt = {['velocity= ',w]};
if length(pos) > 2
output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
end
However now every time I use the cursor to choose the arrow it shows : Error in custom datatip string function. Please see the picture below. What am I doing wrong?
Will be apreciated for any kinda input.

채택된 답변

Changoleon
Changoleon 2016년 11월 25일
편집: Changoleon 2016년 11월 25일
I did not find the answer to my question. Here is what I have done and it kinda works, better than nothing
clc
x=[1 2 3 4 5];
y=[1 2 3 4 5];
u=[3 3 3 3 3];
v=[4 4 4 4 4];
quiver(x,y,u,v,0)
for i = 1:5
[xx,yy] = ginput(2);
velocity=sqrt((xx(2)-xx(1))^2 + (yy(2)-yy(1))^2);
strmin = ['Velocity = ',num2str(velocity),' m/s',[1 1 1]];
t = text(xx(1),yy(1),strmin,'HorizontalAlignment','left');
s = t.FontSize;
t.FontSize = 12;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by