How to plot signal with many legs which has NaN elements

조회 수: 3 (최근 30일)
Takis Akis
Takis Akis 2022년 4월 5일
댓글: David Hill 2022년 4월 5일
I am given a signal with 2 legs that I will have to plot. The plot which confuses me is e.g. for the part of the signal which is: 1/(2-t) for t > 3 and t<5. I create a logical array with only ones at range[3,5] but after I create the output for this leg of the function, when I merge the different legs using addition to get them into one function , I get an error as at some parts I have NaN values (which is obvious, as for t = 2 there is division with zero). How can I get rid of them? I tried using a for loop to only go through the parts I care about but I can't get this to work, and it makes my solution kinda messy. Any suggestions? Thanks
Some code for example:
t = -10:0.1:10;
int1 = (t>-1) & (t<0);
int2 = (t>3) & (t<5);
l2 = int2 .* (1 ./ t);
l1 = ...
final = l1 + l2; % the whole final signal/function representation
plot(t,final); % appears with gaps

답변 (1개)

David Hill
David Hill 2022년 4월 5일
idx=isnan(final);
plot(t(~idx),final(~idx));
  댓글 수: 2
Takis Akis
Takis Akis 2022년 4월 5일
Thanks for answer. It works for plotting, but would there be another more elegent way to do this, maybe by trying to set the NaNs to Zero?
David Hill
David Hill 2022년 4월 5일
final(isnan(final))=0;
plot(t,final);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by