Draw arrow in a plot
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
採用された回答
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 件のコメント
francisco gonzalez
2015 年 5 月 23 日
編集済み: Geoff Hayes
2015 年 5 月 23 日
Thank you very much for your reply, I have almost the result. But I have doubts when using the X, Y coordinates.
The case is as follows:
- I use Matlab GUI to import data and represent it on a graph in real time. Each interval in the X axis corresponds to new data.
- In that imported data matrix, which has a new data every 3 minutes, I impose a condition.
- If the condition is found, then you draw a vertical arrow, with the arrow pointing toward the point where the condition is found.
- The graph where I want to draw arrow, has an X axis (0 to 59) and Y axis (which varies according to the value of the variable)
I tried the following, but I was not successful:
n= length(Variable);
for i=1:n;
if Variable<-2
X=Variable(i);
Y=Variable(i,1);
annotation('arrow',X,Y);
end
end
Perhaps there is other way for do? It is imposible, the arrow appears in middle of picture, ando not where the condition is met
francisco gonzalez
2015 年 5 月 23 日
Maybe other command for display this arrow?
Geoff Hayes
2015 年 5 月 23 日
Francisco - what is Variable? Is it a one-dimensional or a two-dimensional array or something else? What do you mean be the condition of
if Variable < -2
Since Variable is some sort of array, should this condition be true for all elements of Variable or just one element (the ith perhaps)?
Note also that
X=Variable(i);
Y=Variable(i,1);
Won't this mean that X and Y are identical since you are not specifying a column for the X coordinate?
Finally, look closer at the example I provided - X and Y are 1x2 arrays that provide coordinates (i.e. (x,y) pairs) of where the arrow should start and where it should end. Note also that the units of these coordinates are specified in normalized figure units. This means that you have to normalize your coordinates to the figure. So if your x-values are in the interval of [0,59], then to get the coordinate that is "normalized to the figure" you would have to divide it by 59 so that the new interval is [0,1].
The annotation function may not be appropriate for your data set so you may have to come with an alternative means of indicating that your new data point satisfies some condition. Perhaps plot this point with a different colour or shape (circle, star, etc.).
francisco gonzalez
2015 年 5 月 23 日
Thank you very much Geoff, the "Variable" is an array with 59 rows and 1 column. I understand, then, i am having wrong. Can you put one example for see How work the command annotation?. I only want draw a arrow when a value of a array found the condition. For example, "Variable" is an array with values between 6 and -6. When a value is more higher than 6, then arrow. All in real time, a one value entry in array each 3 minutes, but the size of array always is the same.
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.
francisco gonzalez
2015 年 5 月 23 日
Thank you very much Geoff. I am going to study this code and apply to my situation.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
製品
参考
2015 年 5 月 22 日
2015 年 5 月 23 日
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
