sprintf string plus i in matlab

To sprintf a string plus an integer in MATLAB, you can use the following format:

main.m
result = sprintf('string %i', integer)
39 chars
2 lines

Here, string is the string you want to format with the integer integer. %i is a format specifier that indicates where in the string the integer should be inserted.

For example, if you want to sprintf the string "value is 5", where 5 is an integer variable, you can write:

main.m
val = 5;
result = sprintf('value is %i', val)
46 chars
3 lines

The resulting result string would be 'value is 5'.

related categories

gistlibby LogSnag