plot binary vs time
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have 1's and 0's but want 1's to be plotted as a positive number and o's as negative number:
Code:
if(z>0)
a=1;
else
a=0;
end
mn=[t1 a];
2 comentarios
Guillaume
el 3 de Ag. de 2018
"want 1's to be plotted as a positive number"
Which number? +1?
"and o's as negative number"
Which number? -1?
The code snippet you show makes no sense at all and is not commented so we have no idea what its intent is.
Respuestas (1)
Guillaume
el 3 de Ag. de 2018
If you want +1 and -1, why don't you store that in the first place in your vector instead of 1/0?
if zz > 0
a = 1;
else
a = -1;
end
Why go use 0 if you want -1?. If you really do want to do it afterwards for some reason:
%after the loop
mn(mn == 0) = -1;
By the way, there's a lot of variable that get recreated each step of the loop but never change ( t, y, t4). These should be calculated once before the loop. You're just wasting time recalculating the same thing over and over.
Also, the way you construct you mn is very awkward and slow as it gets resized a every step of the loop. Preallocation and indexing would be faster:
%stuff that doesn't need to be calculated in the loop
t=bp/99:bp/99:bp;
y=A*(sin(2*pi*f*t2+pi))%+(sin(2*pi*f*t+pi));
t4=bp/99:bp/99:bp;
%loop preparation,
v = ss:ss:length(m);
mn = zeros(1, numel(v); %preallocation
%loop
for idx = 1:numel(v)
n = v(idx);
mm=y.*m((n-(ss-1)):n);% mm=y.*m((n-(ss-1)):n);
z=trapz(t4,mm); % intregation method
zz=round((2*z/bp));
if zz > 0
mn(idx) = 1;
else
mn(idx) = -1; %or 0 if you really must
end
end
plot(mn);
0 comentarios
Ver también
Categorías
Más información sobre PSK en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!