Clear Filters
Clear Filters

How do I write a line for adding a text to my plot?

4 views (last 30 days)
Hi,
I am trying to add a text to my plot. I tried adding the following line to the code: text('k=28');
I also tried: txt= 'k=28';
Both lines didn't add the text , I am atatching my existing code below. This code is part of the function file.
fig = figure('position', utilities.centerFigPos(1500, 1200));
set(fig, 'Color', 'white', 'defaultLineLineWidth', 2, 'defaultAxesFontSize', 24);
ax = axes(fig);
scatter(ax,X,Y,'o');
line(ax, xFit, yFit);
ax.Title.String = 'Data';
ax.XScale = 'linear';
ax.YScale = 'log';
ax.XLim = [0,1];
ax.YLim = [yMin,1];
ax.YDir = 'reverse';

Answers (1)

Dave B
Dave B on 4 Nov 2021
Edited: Dave B on 4 Nov 2021
The text function requires x and y values (or x, y, z values).
Alternatively, use the title function if you want a title for your plot (I see you already found this by setting the Title.String property)
scatter(randn(100,1),randn(100,1))
text(2,2,"k=28")
title("My Plot")

Tags

Community Treasure Hunt

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

Start Hunting!