Introduction
String formatting helps you create text with numbers or words arranged neatly. It makes your output clear and easy to read.
str = sprintf(formatSpec, A, ...)str = sprintf('Hello %s!', 'world')
str = sprintf('Value: %d', 42)
str = sprintf('Pi approx: %.2f', 3.14159)
str = sprintf('Coordinates: (%.1f, %.1f)', 3.5, 7.2)
name = 'Alice'; age = 30; height = 1.68; info = sprintf('Name: %s\nAge: %d years\nHeight: %.2f meters', name, age, height); disp(info)
sprintf function in MATLAB do?sprintfsprintf is used to create text with values inserted in a specific format.sprintf's role.sprintf formats strings = A [OK]num using sprintf in MATLAB?%d is used for integers in sprintf.num is an integer, %d is correct; others are for strings, floats, or characters.str = sprintf('Value: %0.2f', 3.14159); disp(str);str = sprintf('Name: %s, Age: %d', 25, 'John');sprintf call correctly formats name = 'Laptop' and price = 999.987?%s for string name, %0.2f for float price with 2 decimals.Pass the test and this pattern moves unknown