how to select one first and second sample of a sampled signal?
조회 수: 1 (최근 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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!