Filter löschen
Filter löschen

quiver to show the magnitude of velocity

4 Ansichten (letzte 30 Tage)
Changoleon
Changoleon am 25 Nov. 2016
Bearbeitet: Changoleon am 25 Nov. 2016
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.

Akzeptierte Antwort

Changoleon
Changoleon am 25 Nov. 2016
Bearbeitet: Changoleon am 25 Nov. 2016
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

Weitere Antworten (0)

Kategorien

Mehr zu Vector Fields finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by