I am using Matlab. fprint function gives no error but it does not appear in command window either. Where are results of this command and how to fix it so the output appears as
a=3 b=-2 c=2 d=-2 Input is
a= 3; b=-2; c= 2; d=-2; fprintf( 'a=', num2str(a),'b=', num2str(b), 'c=', num2str(c), 'd=', num2str(d)) Thank you. MM
11 Answer
Essentially you're using the fprintf function wrong, it isn't designed to concatenate strings. You can use [ ] brackets, strcat, or strjoin for that.
Rather than try and work out why you've written it how you have, here is the correct usage:
a = 3; b = -2; c = 2; d = -2; fprintf( 'a=%.0f b=%.0f c=%.0f d=%.0f\n', a, b, c, d ); I'm using the format specifier %.0f to tell fprintf to print a numeric value with no decimal places into the string. The 4 values specified as further inputs are used in these placeholders respectively. The \n is to include a new line at the end.
Output:
a=3 b=-2 c=2 d=-2