How to plot signal with many legs which has NaN elements
이전 댓글 표시
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
2022년 4월 5일
idx=isnan(final);
plot(t(~idx),final(~idx));
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!