フィルターのクリア

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

2 ビュー (過去 30 日間)
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!

採用された回答

Adam Danz
Adam Danz 2019 年 7 月 3 日
編集済み: Adam Danz 2019 年 7 月 3 日
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 件のコメント
Erik Näslund
Erik Näslund 2019 年 7 月 5 日
Thank you very much! This works fine.
Adam Danz
Adam Danz 2019 年 7 月 8 日
Glad I could help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by