How to plot the starting position of time series in MATLAB? - matlab

I have plotted two position (each position is measured in 1ms gap) series data of an object as X coordinate and Y coordinate respectively to get the trajectory of the object.
I have to put an 'X' mark denoting the initial(starting) position of the object.
How should I do it?
plot(X0(trial,saccades(trial,:)>0),Y0(trial,saccades(trial,:)>0),'.','Color','[0.9290 0.6940 0.1250]');
%Formatting
xlabel('X position (deg)');
ylabel('Y position (deg)');
legend('fixations','Saccade');
title('Position for Trial: '+string(trial));
hold off;
This what the graph looks like right now. I need to put 'X' mark to denote the starting x-y position.

Related

how to format radians units in x axis in MATLAB?

I have a data file of 77*1 which is changing based on radians. I plotted my data and its ok in terms of figure itself. however, the x axis turned to be some random numbers. How can I define the thick labels in x axis to be in radians instead of random numbers. please see the figure .
figure
plot(Gamma_dif1, "r","LineWidth",2)
grid on;
ax=gca;
ax. Color='w';
y-axis left
ax.YColor='r';
ylabel('Gamma_difference','Color','r')
You can also create an array: rad = [0:theta/77:theta], where theta is the maximal angle you are plotting. Then, plot it as: plot(rad, Gamma_dif1, "r","LineWidth",2).

How do I calculate the area of a projection created by the command "view"?

How do I calculate the area of a projection? For example, using the following code, I get a projection on the X-Z plane.
[x,y,z]=peaks;
surf(x,y,z);
xlabel('x');ylabel('y');zlabel('z')
view([0,0])
X-Z Plane Projection
I want to be able to determine the area of the projection of any surf plot that I create. Is there a command or function for this?
Short answer
polyarea(x(1,:),max(z))+polyarea(x(1,:),min(z))
Explanation
The plot you want to calculate its area is,
In area calculation you need only the borders of the projection,
plot(x(1,:),max(z))
hold on
plot(x(1,:),min(z),'r')
and the output is,
The total area is the summation of both areas (upper border to x axis and lower border to x axis),
>> polyarea(x(1,:),max(z))+polyarea(x(1,:),min(z))
>> 28.5947
If you want to get the projection area at an arbitrary view angle, you can use the viewmtx function to project the surface onto the viewing plane, and then use boundary and polyarea to extract the boundary and calculate the area. Something like this:
% draw your surface
[x,y,z]=peaks;
surf(x,y,z);
xlabel('x');ylabel('y');zlabel('z')
axis equal;
%extract the viewing angle, and calculate the resulting transformation matrix
[az,el]=view(gca);
T= viewmtx(az,el);
% transform the surface points by this transformation matrix
pts= [x(:),y(:),z(:),ones(numel(x),1)]';
tpts= T*pts;
tpts=(tpts(1:3,:))';
% now "tpts" has the surface points projected onto the viewing plane
figure, plot( tpts(:,1), tpts(:,2), 'bo'); axis equal;
% calculate the border of this region, and calculate its area.
border = boundary(tpts(:,1), tpts(:,2));
projectedArea = polyarea(tpts(border,1), tpts(border,2));
This approach is based off of the help for viewmtx.

Verified if a point is inside a surface matlab

I have a surface interpolating 3D points and I would like to test whether a point is inside or outside this surface.
I know the 3D coordinates of the point and the 3D coordinates of its nearest point on the surface.
For example:
scatter3(1.715710000000000e+02 ,-1.389280000000000e+02, -1.395990000000000e+02,'*','r') % point
hold on
scatter3(1.692480000000000e+02,-1.355325000000000e+02 ,-1.395429000000000e+02,'filled','y') % nearest surface point
hold on
or :
scatter3(1.780790000000000e+02, -1.505310000000000e+02, -1.481070000000000e+02,'*','r') % point
hold on
scatter3(1.795721000000000e+02,-1.346832000000000e+02, -1.499843000000000e+02,'filled','y') % nearest surface point
Plotting these points with surface, both these points seem to be within of the surface...
How can I prove it?
Thanks!

Animating circle to increase and decrease in size over a period of time - matlab

I would like to create a simple visualization whereby the circle (country) will increase/decrease in size(Base on the variables) with respect to time.
How can it be done on matlab with my current dataset ? I would want each circle to represent a country and the size of the circle will be determined by the value in that particular year. C1990 represents year 1990
Can anyhow point me in the right direction or get me started with this ?
Thanks
Here are two possible ways you could start, using scatter (note the AREA of the circles will be proportional to the values of 10*D, not the radius or diameter)
close all
figure(1)
D=rand(10,10)
Cx=1:10;
Cy=Cx;
for i=1:length(D(:,2))
scatter(Cx,Cy,(10*D(:,i)))
drawnow
pause(.1)
end
or plotting the circles manually, with RADIUS of the circle corresponding to D
figure(2)
D=rand(10,10)
Cx=1:10;
Cy=Cx;
phi=0:pi/100:2*pi;
for i=1:length(D(:,2))
for k=1:length(Cx)
r=D(k,i);
plot(Cx(k)+r*cos(phi),Cy(k)+r*sin(phi))
hold on
end
drawnow
pause(.1)
hold off
end
(You can have the area or radius of the circles be proportional to D in either case)

Plotting a rectangular matrix into a circle

I have generated a rectangular matrix with the azimouth angle changing with rows and the radius changing as you change column. These are meant to represent the relative velocities experienced by a rotating helicopter blade. This produces a matrix called Vmat. I want to plot this to appears in a circle (representing the rotation of the blade)
So far I have tried
[R,T] = meshgrid(r,az);
[x,y] = pol2cart(T,R);
surf(x,y,Vmat(r,az));
which should produce a contoured surface showing velocity as it changes with azimouth angle and radius but it comes up with dimension errors.
I don't mind if it is a 2d contour plot or 3d plot i guess both would be written in a similar way.
Thanks
James
The error is in writing Vmat(r,az), presuming that these are actual values of radius and azimuth, not indexes into your radius and azimuth. If you want to take only a subset of Vmat that's a slightly different matter, but this should work:
[R,T] = meshgrid(r,az); % creates a grid in polar coordinates
[x,y] = pol2cart(T,R); % changes those to cartesian for surf
surf(x,y,Vmat);
Alternatively you could do a contour plot:
h = polar([0 2*pi], [0 max(r)]); % set up polar axes with right scale
delete(h) % remove line
hold on
contour(x,y,Vmat);