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.
hello, can i ask you the study case of this problem? thank u so much
Hi, just to add text or number to figure in Matlab for better visualization