How can one, out of several xlines in a script be ignored when the x-input value is missing?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Erik Näslund
am 3 Jul. 2019
Kommentiert: Adam Danz
am 8 Jul. 2019
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!
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 3 Jul. 2019
Bearbeitet: Adam Danz
am 3 Jul. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Geometric Transformation and Image Registration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!