how to select one first and second sample of a sampled signal?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
here I am trying to store and output separatly the first sample and second sample of sampled signal. example, I have a sinewave that I sample at Ts. the first sample I store it and output it sperately and the second sample I do same, then come the third and fourth smaples, and continues so one.
this is the function but I get same as input and no selection has been made
function [y1,y2] = select(u)
y_o1=0;
y_o2=0;
for i=1:2
disp(i)
if i==1
y_o1=u;
else
y_o2=u;
end
end
y1=y_o1;
y2=y_o2;
end
0 commentaires
Réponses (2)
Guillaume
le 20 Jan 2020
I'm not sure what you are trying to achieve with the code you have written, it doesn't make much sense I'm afraid.
The whole lot simplifies to:
function [y1, y2] = select(u)
y1 = u;
y2 = u;
end
which just copies u into two new variables. Not very useful.
However, I suspect you meant to do:
function [y1, y2] = select(u)
y1 = u(1); %get first element
y2 = u(2); %get second element
end
But even that is not very useful. There's no reason to create two new variables just to copy the first two elements of something. Wherever you were going to write y1, you can just write u(1) and not bother with the copy.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!