Matlab: How to plot 'text'

In summary, to plot text in Matlab, use the text() function with coordinates and the desired text. You can also change the font, style, and color of the text. To add multiple lines, use the \n character. You can rotate text and add text boxes or annotations with the textbox() or annotation() functions.
  • #1
rsq_a
107
1
I want to be able to display continually updated numbers on a plain figure environment. For example, a cheap way to do this is:

Code:
figure(1)
for j = 1:10
  title([ 'Hello'; num2str(j) ])
end

This prints out a two-liner ('Hello' and a number) in the title portion of the figure.

I want the same thing, but with no actual white plot. In other words, I just want the gray figure window, and updated figures.

How would I do this?
 
Physics news on Phys.org
  • #2
Something like to following

Code:
figure(1)
set(gca,'Visible','off')

for j=1:10
  text(0,0,num2str(j)
  cla
end


should work
 
  • #3


There are a few ways to achieve this in Matlab. One option is to use the "text" function to create text objects within the figure. This allows you to specify the position of the text on the figure and update it with new numbers as needed. Here is an example code:

figure(1)
axis off % this removes the axis and plot, leaving only a blank figure
for j = 1:10
text(0.5, 0.5, ['Hello ' num2str(j)], 'FontSize', 16) % specify the position and text to display
pause(1) % this pauses the loop for 1 second before updating the figure
end

Another option is to use the "annotation" function to add text annotations to the figure. This allows for more customization, such as specifying the font and color of the text. Here is an example code:

figure(1)
axis off
for j = 1:10
annotation('textbox', [0.5, 0.5, 0.1, 0.1], 'String', ['Hello ' num2str(j)], 'FontSize', 16) % specify the position and text to display
pause(1)
end

Both of these methods will allow you to continually update the text on a plain figure environment without any actual plot. I recommend exploring the documentation for the "text" and "annotation" functions for more details and options.
 

1. How do I plot text in Matlab?

To plot text in Matlab, you can use the text() function. This function takes in the coordinates of where you want the text to be located on the plot, as well as the text itself.

2. Can I change the font or style of the text?

Yes, you can change the font and style of the text by using additional parameters in the text() function. For example, you can specify the font size, font style (bold, italic, etc.), and color of the text.

3. How can I add multiple lines of text to my plot?

To add multiple lines of text, you can use the \n character to indicate a line break within the text string. For example, text(x, y, 'Line 1\nLine 2') will display "Line 1" and "Line 2" on separate lines.

4. Is it possible to rotate the text on my plot?

Yes, you can rotate the text by specifying a rotation angle in degrees in the text() function. For example, text(x, y, 'My Text', 'Rotation', 45) will rotate the text 45 degrees clockwise.

5. Can I add a text box or annotation to my plot?

Yes, you can add a text box or annotation to your plot using the textbox() or annotation() functions. These functions allow you to add more customizable text elements to your plot, such as boxes, arrows, and connectors.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
951
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top