how to select one first and second sample of a sampled signal?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Guillaume
2020-1-20
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!