Effacer les filtres
Effacer les filtres

How can one, out of several xlines in a script be ignored when the x-input value is missing?

2 vues (au cours des 30 derniers jours)
I have several datasets stored as different workspaces. I need to plot these data and mark specific timepoints of blood sampling with an xline. Since there are many plots to be done, I have tried to automate this by using a script in which I only have to note the time that is to be highlighted.
My problem is, for different plots different data samplings is missing. For example:
x = linspace(0,100,10)
y = randi([0 10],1,10)
plot(x,y)
a = input('1:')
b = input('2:')
c = input('3:')
xline(a,'-k')
xline(b,'-r')
xline(c,'-b')
If one of the three timepoints ("1-3") is missing, I want to skip that entry by pressing 'Enter'. How can I get the script not to execute/draw the xline with the missing x-value (or empty array [ ] that is created with the blank input)?
Thank you in advance!

Réponse acceptée

Adam Danz
Adam Danz le 3 Juil 2019
Modifié(e) : Adam Danz le 3 Juil 2019
You can plot all lines at the same time, skipping empty values. Then you can set the colors of the line.
a = input('1: ');
b = input('2: ');
c = input('3: ');
xlh = arrayfun(@(x)xline(x,'-'),[a,b,c]);
colors = {'k','r','b'};
set(xlh, {'color'}, colors(~cellfun(@isempty,{a,b,c}))')
*This solution was updated after realizing that xline() does not accept NaN values.
  4 commentaires

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Geometric Transformation and Image Registration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by