How to delete previous values recorded?

11 views (last 30 days)
hello, it would be of great help if anybody could tell me how to delete previous values recorded by matlab once my loop has reached the value that i needed it to, therefore having a new set of values, because my program is just recording all the values, inclusive the non-desired values and then plotting them, this way reducing accuracy in the graph visual because it is must larger and over a large space of time. thanks in advance luis

Accepted Answer

the cyclist
the cyclist on 10 Apr 2013
It is not perfectly clear to me what you mean. You might want to show us some code. However, here is a guess at what you want:
Suppose you have a vector A of length 102, and you only want to keep the first 100 elements. Each of the following methods would work:
A = A(1:100);
or
A(101:102) = [];
or
A(end-1:end) = [];
  1 Comment
luis
luis on 11 Apr 2013
oh right, i understand what you mean, so how do you reckon i should input it in here? because basically im trying to delete all but the end value because i want to keep the displacement values at the last value of the angle but it will just delete it all, there must be something im doing wrong. CODE
for I=1:10*tp
D(I+1)=(rho(I)*(vv(I)^2)*Cd*A)/(-2); %Drag at every point until parachute deployment
ax(I+1)=(D(I)*cos(angle(I)))/m; %Acceleration in x-axis at any point until parachute deployment
ay(I+1)=(D(I)*sin(angle(I))-m*g)/m; %Acceleration in y-axis at any point until parachute deployment
aa(I+1)=sqrt((ax(I+1))^2+(ay(I+1))^2); %Modulus of acceleration at any point until parachute deployment
vx(I+1)=vx(I)+dt*ax(I); %Velocity in the x-axis at any point until parachute deployment
vy(I+1)=vy(I)+dt*ay(I); %Velocity in the y-axis at any point until parachute deployment
x(I+1)=x(I)+dt*vx(I); %Displacement in the x-axis at any point until parachute deployment
y(I+1)=y(I)+dt*vy(I); %Displacement in the y-axis at any point until parachute deployment
max_displacementx_of_vector=max(x(I+1)); %Syntax to calculate maximum value of displacement vector, for plotting purposes
max_displacementy_of_vector=max(y(I+1)); %Syntax to calculate maximum value of displacement vector, for plotting purposes
vv(I+1)=sqrt(vx(I)^2+vy(I)^2); %Modulus of velocity at any point until parachute deployment
rho(I+1)=roi*(1-2.333*10^(-5)*y(I+1))^5; %Changing density as a result of height increase
if y(I+1)>42850 %If statement to break the loop in case of a height increase of 42850 due to that formula no longer being valid
break
end
angle(I+1)=atan(vy(I)/vx(I)) %By using the inverse tangent of velocity in the y-axis divided by the x-axis we obtain the new angle for the drag formula
degrees=(angle(I)*360)/2*pi; %Formula to convert the theta angle from radians to degrees for ease of reading purposes
t=t+dt; %By using this formula we obtain the desired iterations
%----------------------------PLOTTING OF THE TRAJECTORY PRIOR TO PARACHUTE------------------------------%
%plot(a,'g*',b)
plot(t,max_displacementx_of_vector,'g*','LineWidth',5)
plot(t,max_displacementy_of_vector,'b+','LineWidth',1/2)

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 10 Apr 2013
To delete an entire variable:
clear('yourArray', 'yourOtherArray');
to delete just some indexes:
indexesToDelete = 4:10; % or whatever.
yourArray(indexesToDelete) = [];

Community Treasure Hunt

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

Start Hunting!