How to plot signal with many legs which has NaN elements

3 visualizaciones (últimos 30 días)
Takis Akis
Takis Akis el 5 de Abr. de 2022
Comentada: David Hill el 5 de Abr. de 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

Respuestas (1)

David Hill
David Hill el 5 de Abr. de 2022
idx=isnan(final);
plot(t(~idx),final(~idx));
  2 comentarios
Takis Akis
Takis Akis el 5 de Abr. de 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?
David Hill
David Hill el 5 de Abr. de 2022
final(isnan(final))=0;
plot(t,final);

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by