Reputation: 109
My question is similar to the post: matlab curve with label
I have some data (acquired using a function too long to show here), which gives me 2 arrays: Nv4 (337x1) and t (337x1) and I want to plot 'a=40' on the plot line. I should be able to use contour label, but I need to convert my data as matrix format first. The post above gives a link to explain how to convert our data, unfortunately the link has expired and I have no idea how I should convert my data to. An example would be useful !
I'm posting this as a new question because I don't have enough reputation to post a comment
Upvotes: 3
Views: 13154
Reputation: 5188
I guess there is another way, simply with text
. Here is a sample:
% Create a sample curve
x = 1:337;
y = sqrt(x);
plot(x,y);
% Define position to display the text
i = round(numel(x)/2);
% Get the local slope
d = (y(i+1)-y(i))/(x(i+1)-x(i));
X = diff(get(gca, 'xlim'));
Y = diff(get(gca, 'ylim'));
p = pbaspect;
a = atan(d*p(2)*X/p(1)/Y)*180/pi;
% Display the text
text(x(i), y(i), 'a=40', 'BackgroundColor', 'w', 'rotation', a);
And here is the result:
Best,
Upvotes: 10