how to plot with line ?

1 回表示 (過去 30 日間)
Niki
Niki 2014 年 5 月 13 日
コメント済み: dpb 2014 年 5 月 15 日
I have some selected point which I would like to show with line for example I import my data as follows:
load spectra
wl=[ 900:2:1700];
t1=[181 185 226 308 325] % First set of selected points
t2= [204 207 209 222 240 260 277 303]
then I try to plot them.
plot (wl, NIR)
hold on
ylim([-0.6 1.5])
plot (wl(1,t1),-0.2,'.b')
plot (wl(1,t2),-0.4 ,'.r')
But I want to plot it as follows:
Does anyone know how to do it? how to add those lines (not manually ?)

採用された回答

dpb
dpb 2014 年 5 月 14 日
y1=[wl.NIR(3,t1); -0.2*ones(size(t1))]; % and y
??? Attempt to reference field of non-structure
Why did you put the 'w1' in front of NIR()? You loaded NIR directly as we already had established; you've got to use the variables that are in your workspace, not mine.
y1=[NIR(3,t1); -0.2*ones(size(t1))];
  2 件のコメント
Niki
Niki 2014 年 5 月 15 日
I accept but you need to change something , however I managed to plot it; Thanks dear
dpb
dpb 2014 年 5 月 15 日
Show your code where you had a problem--worked just fine here.
OK, I guess your 'w1' is actually 'wl' (a lowercase 'L' instead of a 'one') that I guessed when I did the edit.

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

その他の回答 (1 件)

dpb
dpb 2014 年 5 月 14 日
編集済み: dpb 2014 年 5 月 14 日
OK, starting over -- I looked at your plot and see you really didn't use arrows at all--that makes it much simpler. Why TMW can't have an arrow that works much more easily is beyond me, but...
Start off as did before...presume you've already done the plot and ylim stuff--
hold on % hold the plot to add onto it..
x1=[w1(t1); w1(t1)]; % the first set of x points
y1=[NIR(3,t1); -0.2*ones(size(t1))]; % and y
line(x1,y1,'color','b') % the vertical lines
scatter(x1(2,:),y1(2,:),'filled','facecolor','b','marker','d') % and the markers at the ends
Now just repeat for the other set...
x2=[w1(t2); w1(t2)];
y2=[NIR(3,t2); -0.4*ones(size(t2))];
line(x2,y2,'color','r')
scatter(x2(2,:),y2(2,:),'filled','facecolor','r','marker','d')
So, if you're happy w/ this appearance, you can forget about the annotation stuff. I was trying to make it an arrow pointing down as thought at first glance that's what you'd drawn in your sample.
  3 件のコメント
dpb
dpb 2014 年 5 月 14 日
f was the frequency vector, 'dat' the structure name for the data...use your names in place; I guess you used w1 and didn't create a structure so it's NIR Figured that would be obvious.
Niki
Niki 2014 年 5 月 14 日
I don't have frequency vector. I have frequency matrix named NIR x1=[NIR(t1); NIR(t1)];
when i use
hold on % hold the plot to add onto it.. x1=[NIR(t1); NIR(t1)]; % the first set of x points y1=[wl.NIR(3,t1); -0.2*ones(size(t1))]; % and y line(x1,y1,'color','b') % the vertical lines scatter(x1(2,:),y1(2,:),'filled','facecolor','b','marker','d') ??? Attempt to reference field of non-structure array.
I will get error

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

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by