MATLAB: Use a variable in Request user input prompt.

inputrequestwrong format specifier

I am trying to use the Request User Input command with a changeable message for every iteration. For example:
1 prompt=sprintf('For file %f give the value for x',filename)
2 x = input(prompt)
However filename is a 1×23 char and I don't get the result I get. The code I use, treats filename as a
Any solutions?

Best Answer

  • The identifier you are using in sprintf (%f) stands for floating point, but you want a char array so use the identifier %s.
    >> filename = 'abcdef.csv';
    >> prompt=sprintf('For file %s give the value for x',filename)
    prompt =
    For file abcdef.csv give the value for x