Academic world

How to Add Text or Number to Figure in Matlab

Hello everyone and welcome!

In this post, I’m going to show you a simple method to add text or number to Figure or Plot in Matlab. It’s very easy and effective.

If you want to download this Matlab code, please check the link in the video description. If you have any questions, please let me know by leaving a comment below.

Now, let’s get started.

Matlab code

clc
clear all
close all
% City locations of TSP
Data=[1 39.57 26.15
      2 36.26 23.12
      3 33.48 10.54
      4 37.56 12.19
      5 38.42 13.11
      6 37.52 20.44];
[x y] = size(Data);

title('Visualization of a random TSP route');
xlabel('X cooridnate')
ylabel('Y coordinate')
hold on
plot(Data(:,2),Data(:,3),'^r','MarkerSize',10,'LineWidth',2)
 
for i=1:x
    text(Data(i,2)+0.3,Data(i,3)+1.2, num2str(i),'FontSize', 15);
    text(Data(i,2)-0.3,Data(i,3)+1.2, 'city','FontSize', 15);
end
line(Data(:,2),Data(:,3),'LineStyle', '-', 'LineWidth',2);

P/s: If you find the post useful, share it to remember and to help other people as well.

Dr.Panda

View Comments

Recent Posts

Adaptive Re-Start Hybrid Genetic Algorithm in Matlab

Hello everyone! In this post, I am going to show you my innovative version of…

2 weeks ago

Test Your Understanding About Genetic Algorithm (Test 2)

Hello everyone. Let’s take a test to check your understanding about genetic algorithm, with multiple…

4 weeks ago

Adaptive Restart Hybrid Genetic Algorithm

Hello everyone! In this post, I am going to show you my innovative version of…

1 month ago

Adaptive Re-Start Hybrid Genetic Algorithm (Test the Performance in Case Studies)

Hello everyone. In this post, I am going to show you my innovative version of…

8 months ago

Adaptive Re-Start Hybrid Genetic Algorithm in Matlab

Hello everyone! Let’s see how my innovative version of Genetic Algorithm, called Adaptive Re-start Hybrid…

8 months ago

Crypto Quiz (Test Your Knowledge About Cryptocurrency)

Hello everyone! Let’s take a short quiz, to test your knowledge about crypto-currency, or crypto.…

12 months ago