How can I remove repeating values from the vector?

Hi,
I've got a loop that simulates Simulink model, collects the data and plots everything on the graphs, here is simplified code:
for v = 4:3:26
air_velocity = v;
while abs(old_u - new_u) >= errortolerance % siumlate untill model converges
simOut = sim('TurbineWithVariablePitch_new_.slx',time);
umax = round(max(simOut.Velocity), 2);
old_u = new_u;
new_u = umax;
disp(['Current iteration: ',num2str(iteration), ' for time: ', num2str(time, '%10.5e') ])
if abs(old_u - new_u) <= errortolerance
cprintf('*blue',['Solution fully converged with the current error of ', num2str(abs(old_u - new_u))]);
cprintf('\n');
else
disp(['Solution did not converged with the current error of ', num2str(abs(old_u - new_u))])
end
if iteration >= maxiteration
cprintf('*red','Solution did not converged\n');
break
end
iteration = iteration +1;
time = time + timestep;
end
simulationtime = [0:0.01:2000];
a = round(simOut.AoA.signals.values);
n=max (numel(simulationtime)); %make the vectors the same size
u(end+1:n)=nan;
a(end+1:n)=nan;
AoAout = [AoAout , a]; %add to the results
SimulationTime = [SimulationTime , simulationtime'];
end
f4 = figure('Name','AoA vs Time');
plot(SimulationTime, AoAout, 'linewidth', 2);
ylabel('AoA (deg)');
xlabel('Time (s)');
The problem is, I'm getting repitetive values for AoA:
They are not always the same so unique command doesn't work... I've been stuck on this problem for a while. I'm fairly new to MATLAB and tring to achieve something similar to this:

6 Comments

You are plotting AoA vs Time while the example you are trying to recreate is AoA vs Azimuth.
Yes I'm aware of that but since everything comes from simulink, everything is a function of time. I'm getting the same issue when I'm trying to plot it against position as the model gets the values at different times because the velocity slightly vary with time. Meaning if I have velocity of 2*pi rad/s and in the X time I'll get position 0, after 1 second I won't get 0 but some other value.
I'll leave this as a comment instead of an answer since I'm not sure what to do next. However, it appears your data is cyclical with azimuth angle. Thoughts I have:
  1. Select a single 0-360 azimuth angle cycle to plot
  2. Average all the cycles, resulting in a single line. This will also hopefully remove the lines connecting the beginning to the end of each line.
How do I average all of the cycles?
Still have no clue how to do it. I'm alredy using round() function to get the values. I've tride to define position as a single vector from 0 to 360, does'n work.
How can I select single cycle? Or how can I average them?
Hi, I'm actually really desperate for the solution and still haven't figured it out.

Sign in to comment.

 Accepted Answer

So... I found the solution. It may not be the most elegant but it works. The code goes troug the vector untill it finds the value that's smaller than 10. Then it starts saving the values untill it reaches 350. After that it fills the rest with NaN.
position=[];
CountOn = 0;
row=1;
End = 0;
for x = 1:1:1000
b=p(row);
d=NaN;
if b <= 10
CountOn = 1;
end
if CountOn == 1
d=b;
end
if b>=345 && CountOn==1
CountOn = 0;
End=1;
end
if End == 1
d=NaN;
end
position=[position, d];
row=row+1;
end
position = position';
Posting if anyone will encouter the same issue.

1 Comment

I've optimised the code a bit:
position=[];
CountOn = 0;
row=1;
End = 0;
newb = 10;
for x = 1:1:1000
oldb=newb;
newb=p(row);
d=NaN;
if newb > oldb && oldb < 10
CountOn = 1;
end
if CountOn == 1
d=oldb;
end
if newb<oldb && CountOn==1
CountOn = 0;
End=1;
end
if End == 1
d=NaN;
end
if row > 1
position=[position, d];
end
row=row+1;
end
position = position';

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!