Try:
disp(['The new values of x and y are ', num2str(x), ' and ', num2str(y), ', respectively']);
You can also omit commas, but IMHO they make the code more readable.
By the way, what I did here concatenates 5 lines together to form a single line, and then sent that single line to the disp function. Note that I essentially concatenated the string using the same syntax you can use with numeric matrices, i.e. [x, y, z] . The reason I can do this is because matlab stores character strings inside AS numeric string vectors, with each character representing an element. Thus, the above operation essentially combines 5 numeric row vectors horizontally!
One more point: your code did not work, because Matlab processed your num2str (x) as a string, and not as a function. In the end, you may legitimately want to type "num2str (x)" rather than evaluate it with a function call. In my code, the first, third, and fifth lines are defined as lines, and the second and fourth are functions that evaluate the lines.
source share