Adding text to the plot values in the plot

Hi..Am plotting the different values of slopes of lines in a single plot .But I want to indicate each plotted value with the respective line number how can I do this.. previously I am storing slope values in slope(K).. then am using
for k=1:n
plot(slope,'*')
end
Can someone suggest about this...

1 件のコメント

Image Analyst
Image Analyst 2011 年 10 月 10 日
Why do you need/want the for loop? The plot function call will plot the whole thing - the whole slope array. You're just plotting the whole thing n times.

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

 採用された回答

Walter Roberson
Walter Roberson 2011 年 10 月 10 日

0 投票

Either use legend(), or text() a label in place somewhere along the line.

9 件のコメント

Gova ReDDy
Gova ReDDy 2011 年 10 月 10 日
By using legend I tried.
But I was able to plot line joining the points.But how can I denote the points with line number.
can you please tell me this..
Walter Roberson
Walter Roberson 2011 年 10 月 10 日
for k=1:n
text(x(k),y(k),num2str(k));
end
Gova ReDDy
Gova ReDDy 2011 年 10 月 11 日
Danx....
Bt when am using this
if (ycoord && xcoord >=0)
Then am getting error like this
"operands to the && operators must be convertible to logical scalar values"
Walter Roberson
Walter Roberson 2011 年 10 月 11 日
Insufficient information. Your previous code did not show any ycoord or xcoord, and you did not show what you want to do in the situation where the test is true, so I am not able to recommend a solution.
The error you see is consistent with ycoord or xcoord not being scalars. The && operator can only be used with scalars.
Note by the way that your code is equivalent to
if (ycoord ~= 0 && xcoord >=0)
Gova ReDDy
Gova ReDDy 2011 年 10 月 12 日
Sorry...My code is this
Calculating coordinates for multiple Images
[ycoord,xcoord]=find(Image);
if ((ycoord)>0 &&(xcoord) >0)
calculating slope(k);
else
slope(K)=0;
end;
Walter Roberson
Walter Roberson 2011 年 10 月 12 日
It is not possible for find() to return 0 or negative coordinates. If it does not find anything, then it returns empty arrays.
find() will, in general, return more than one location. It is not obvious from your code what you want to do with those multiple locations in order to calculate a single slope ?
Gova ReDDy
Gova ReDDy 2011 年 10 月 20 日
When there is a output(x,y coord) from find() i.e., when there is a line in the current frame of video then it is calculating the slope.
But when there is no line in the current frame of the video then I have to make that frame slope as zero So,how can I make this..
Walter Roberson
Walter Roberson 2011 年 10 月 20 日
isempty() can tell you whether there was a result from find() or not.
But again, what if there were (say) 5 values found?
Gova ReDDy
Gova ReDDy 2011 年 10 月 20 日
Am plotting the "slope" value against "frames".
for k = 1 :240 %no.of frames
%Here in loop am extracting the line from each frame then
[ycoord,xcoord]=find(line);%finding the coordinates of line
Ymax(k)=max(ycoord);
Ymin(k)=min(ycoord);
Xmax(k)=max(xcoord);
Xmin(k)=min(xcoord);
slope(k)=(Ymax(k)-Ymin(k)/Xmax(k)-Xmin(k));%slope=y2-y1/x2-x1
end;
plot(slope,'-ro');%plotting slope values of frames
xlabel('Fame number');
ylabel('SLOPE Of Line In the Frame ');
title('SLOPE PLOT of the VIDEO');
when there is no line in the next frame then the slope value should be zero..
else it should calculate the slope value .

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

その他の回答 (1 件)

Gova ReDDy
Gova ReDDy 2011 年 10 月 24 日

0 投票

This is working
if((isempty(xcoord)=1) && (isempty(xcoord)=1))
then
caluclate slope
else
slope=0;
end

カテゴリ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by