Reputation: 3
I need to plot straight lines in-between points. Further I want to label those lines with numbers. It all works fine, but as soon as I have one-digit numbers AND two-digit numbers (e.g. 5
and 30
) the displayed number in the plot is only 3
.
How do I make MATLAB plot the full digit number?
My MATLAB code is:
numbers_string = num2str(numbers)
for i = 1 : number_of_lines
plot3([x_start(i); x_end(i)],[y_start(i); y_end(i)],[z_start(i); z_end(i)], '-k');
text((x_start(i)+x_end(i))/2, (y_start(i)+y_end(i))/2, (z_start(i)+z_end(i))/2, numbers_string(i))
end
The length of the number_of_lines
and the numbers_string
is the same, so my plot is working fine, just the labelling is causing problems.
I tried formatting but it did not work either.
Upvotes: 0
Views: 141
Reputation: 1587
The i
-th entry of a string will be a single character. For example, if
numbers = [42 99 1];
num_str = num2str(numbers);
then num_str(1)
, num_str(2)
and num_str(3)
will be '4'
, '2'
and ' '
.
Instead of
number_str = num2str(numbers)
text(x,y,z,num2str(numbers_str(i)))
consider
text(x,y,z,num2str(numbers(i)))
Upvotes: 2