2

I am trying to print multiple variables to the command window with accompanying text. disp does not seem to want to work, nor does fprintf. Does anyone have any idea how i can do this. I am trying to print code to look like the following, inserting variables in between text

print('The minimum value is', minY1(2), 'which occurs at x = ', minX);

which would, for example, result in

The minimum value is 69.054, which occurs at x = 5

Cheers

John Connor
  • 41
  • 1
  • 3

2 Answers2

3

Try this:

fprintf('The minimum value is %d which occurs at x = %d', minY1(2), minX);

%d is used for numbers and %s would be used for strings.

diiN__________
  • 7,393
  • 6
  • 42
  • 69
0

disp probably didn't produce what you want because you need to explicitly convert the numbers to text. You can try:

disp(['The minimum value is ' num2str(minY1(2)) ', which occurs at x = ' num2str(minX)]);
Rob
  • 66
  • 1