Writing data on a blank figure
15 views (last 30 days)
Show older comments
I want to generate a blank figure/image and write a text and variable value using a for loop. For example, writing X:y where X is just a text (which does not change) but value of y is written from a variable and it keeps changing with each iteration. I tried using 'text' but have not got the output i want.
Thanks.
0 Comments
Answers (2)
KSSV
on 6 Mar 2018
N = 10 ;
figure
hold on
x = 0.5 ;
for i = 1:N
y = rand ;
plot(x,y,'.r')
text(x,y,num2str(i))
end
Walter Roberson
on 6 Mar 2018
text() does that for display purposes. But if you are aiming for an image you would have to capture the axes content with getframe() or saveas() or print() to use text()
If you need an image then the alternative is to use the Computer Vision Toolbox with its insertShape and insertText functions.
6 Comments
Walter Roberson
on 8 Mar 2018
Edited: Walter Roberson
on 8 Mar 2018
Is it possible that text_str is a cell array rather than a character vector or string object ? If so then you would need text_str{7} rather than text_str(7)
This presumes that if text_str is a cell, that text_str{7} only contains a single row of text.
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!