Draw arrow in a plot
308 ビュー (過去 30 日間)
古いコメントを表示
francisco gonzalez
2015 年 5 月 22 日
コメント済み: francisco gonzalez
2015 年 5 月 23 日
Hi all, i have a question. I am creating a GUI that import real time data. I want draw a vertical line or a arrow if a condition is met.
For example:
n=length(p);
for i=1:n;
if p>100 && t>100
annotation=('arrow');
end
end
Is this correct for draw arrow in a plot in real time?
Thank you very much
0 件のコメント
採用された回答
Geoff Hayes
2015 年 5 月 23 日
annotation=('arrow');
would not work since you are assigning the string arrow to a variable called annotation. Instead you would want to do something like
X = [0.5 0.5];
Y = [0 0.5];
annotation('arrow',X,Y);
which would draw an arrow starting at the coordinate (0.5,0) and ending at (0.5,0.5). (Note that the coordinates are specified in normalized figure units which means that the arrow would be drawn in the middle.)
While you need not provide the X and Y inputs to this function, be aware that the default values will be used in place (of them) so the arrow may not be drawn where you expect it to be.
6 件のコメント
Geoff Hayes
2015 年 5 月 23 日
Are there lower and upper bounds for your Variable array? I realize that the example indicates that the values will be between -6 and +6 but that you want to draw an arrow at some point that is greater than six.
If we assume that the minimum value for y is -6 and that the maximum is 100, then we could do the following
% create a figure and set the axes limits
figure;
minX = 1; maxX = 59;
xlim([minX maxX]);
minY = 0; maxY = 6; upperY = 100;
ylim([minY upperY]);
Now we have to handle the incoming data in Variable or (in my example) varData.
% create some random data that is in the interval [-6, 6].
varData = minY + rand(1,maxX)*(maxY - minY);
% set two of these values to be greater than 6
varData(23) = 19;
varData(42) = 91;
% find those values in varData that are greater than 6
dataOutsideOfInterval = varData > maxY;
if any(dataOutsideOfInterval)
xIdcs = find(dataOutsideOfInterval==1);
for k=1:length(xIdcs)
x = xIdcs(k)/maxX;
y = (varData(xIdcs(k))-minY)/(upperY-minY);
annotation('arrow',[x x], [(maxY-minY)/(upperY-minY) y]);
end
end
The above doesn't quite work the way I would like as it seems to take into account the complete figure and not the axes (so the arrows aren't exactly starting and pointing where I would like). But you should be able to start with this and find a good solution.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!