How to plot signal with many legs which has NaN elements

2 Ansichten (letzte 30 Tage)
Takis Akis
Takis Akis am 5 Apr. 2022
Kommentiert: David Hill am 5 Apr. 2022
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

Antworten (1)

David Hill
David Hill am 5 Apr. 2022
idx=isnan(final);
plot(t(~idx),final(~idx));
  2 Kommentare
Takis Akis
Takis Akis am 5 Apr. 2022
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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by