num2str error in random walk plot

I received this error when trying to plot a random walk and title it with a number:
"Error in matlab.graphics.interaction.actions.Linger
Warning: Error occurred while executing the listener
callback for event ButtonExited defined for class
matlab.graphics.primitive.canvas.JavaCanvas:
Execution of script num2str as a function is not
supported:
/Users/Rocketroos/MATLAB-Drive/QuadrantofSubplotsExample/num2str.m
Error in timer (line 133)
obj.Name = ['timer-'
num2str(mltimerpackage('Count'))];
Error in
matlab.graphics.controls.ToolbarController/createTooltipTime"
My code:
N = 1000;
%p is the probability for the person to step forward
p =0.5;
position (1) = 0;
for i = 2:N
number =rand;
if number > p
position(i) = position (i-1)+1;
else
position(i) = position (i-1)-1;
end
end
plot (position)
%for adding text to a number
%Name the string in front of the word string
EndPositionString = num2str(solution(N));
title (['End Position = ', EndPositionString])

 Accepted Answer

You need to remove /Users/Rocketroos/MATLAB-Drive/QuadrantofSubplotsExample from your MATLAB path, or else you need to rename /Users/Rocketroos/MATLAB-Drive/QuadrantofSubplotsExample/num2str.m to something else.
The code there is interfering with using MATLAB's num2str() function.

More Answers (0)

Products

Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!