Question

Please help me out with this. This plot gives the mobile users that are moving. Now, I am trying to add a few constant points in the plot. Like the base stations for the mobile users '*'. I want to put say a '#' for every base station and put like around 10 of them.

function test_Animate(s_mobility,s_input,time_step)

v_t = 0:time_step:s_input.SIMULATION_TIME;

for nodeIndex = 1:s_mobility.NB_NODES
    %Simple interpolation (linear) to get the position, anytime.
    %Remember that "interp1" is the matlab function to use in order to
    %get nodes' position at any continuous time.
    vs_node(nodeIndex).v_x =  interp1(s_mobility.VS_NODE(nodeIndex).V_TIME,s_mobility.VS_NODE(nodeIndex).V_POSITION_X,v_t);
    vs_node(nodeIndex).v_y = interp1(s_mobility.VS_NODE(nodeIndex).V_TIME,s_mobility.VS_NODE(nodeIndex).V_POSITION_Y,v_t);

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure;

hold on;

for nodeIndex = 1:s_mobility.NB_NODES
    vh_node_pos(nodeIndex) = plot(vs_node(nodeIndex).v_x(1),vs_node(nodeIndex).v_y(1),'*','color',[0.3 0.3 1]);
end
title(cat(2,'Simulation time (sec): ',num2str(s_mobility.SIMULATION_TIME)));
xlabel('X (meters)');
ylabel('Y (meters)');
title('Random Waypoint mobility');
ht = text(min(vs_node(1).v_x),max(vs_node(1).v_y),cat(2,'Time (sec) = 0'));
axis([min(vs_node(1).v_x) max(vs_node(1).v_x) min(vs_node(1).v_y) max(vs_node(1).v_y)]);
hold off;
for timeIndex = 1:length(v_t);
    t = v_t(timeIndex);
    set(ht,'String',cat(2,'Time (sec) = ',num2str(t,4)));
    for nodeIndex = 1:s_mobility.NB_NODES
                          set(vh_node_pos(nodeIndex),'XData',vs_node(nodeIndex).v_x(timeIndex),'YData',vs_node(nodeIndex).v_y(timeIndex));
    end

    drawnow;
  end

end

The complete submission of this can be got in the MATHworks site. http://www.mathworks.in/matlabcentral/fileexchange/30939-random-waypoint-mobility-model

Please help me out.

Was it helpful?

Solution

Here's the basic idea. In the following, fixed_x and fixed_y are vectors of equal length giving the location of your fixed points. moving_x and moving_y are matrices of size t x n where t is the number of time steps, and n the number of points.

%plot the fixed points
plot(fixed_x,fixed_y, 'p'); 
hold on
%plot the first set of moving points
h = plot(moving_x(1,:),moving_y(1,:),'r*'); 

Then, to move the points, we use the handle to the moving points, h to set XData and YData values. This would be within a loop where n is the time step:

set(h, 'XData',moving_x(n,:),'YData',moving_y(n,:));
%may need drawnow;

If you want to be able to see the points moving, you may need to add some pause command - otherwise it might cycle through the update loop so quickly you won't see anything except the final set of positions. On the other hand, you could just save out the figure as an image file after you've moved the points with set, or add it as a frame to a movie, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top