Shika93
Shika93

Reputation: 659

Text or annotation in a plot

Since I don't understand how notations work, I just need to add in a plot the mean value and add a label to write the point. I added the white star

scatter(azimuth,elevation,'r'),'filled';
hold on;
plot(az_mean,el_mean,'wp'); hold on;

then I added the label with

str = {az1_mean,el1_mean};
text (az1_mean,el1_mean,str);

but the two values are in two different lines. How can I get this format (az1_mean,el1_mean)?

x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);  
y_mean = mean(y); x_mean = mean(x)    
h1 = figure(1);
scatter(x,y)
xlabel('Azimuth); ylabel('Elevati');
hold on;
plot(x_mean,y_mean,'wp'); hold on;
str = {x_mean,y_mean};
text (x_mean,y_mean,str);
hold off;

Upvotes: 1

Views: 101

Answers (1)

Sardar Usama
Sardar Usama

Reputation: 19689

In the text function, if you give the text argument as a cell array, the new row/column in the cell array will be considered as a new line for text. Take a look at this example.

To fix your problem, just explicitly convert both of x_mean and y_mean into character arrays and concatenate them with brackets outside and a comma in between i.e

text(x_mean, y_mean, ['(', num2str(x_mean), ', ', num2str(y_mean), ')']);

output

By the way, there is no need of multiple hold ons. A single hold on will keep holding on unless you hold off.

Upvotes: 1

Related Questions