Hi dagan,
As per my understanding, you want to improve the syntax of the command and make it more readable.
sprintf can be useful for formatting strings with variable values, but it may seem cumbersome in this case. So, you can directly concatenate the string expressions using string concatenation (+ operator) in MATLAB as shown below.
x_1 = num2str(X(1)) + "cos(" + num2str(w_n(1)) + "t+" + num2str(phi(1)) + ") + " + num2str(X(2)) + "cos(" + num2str(w_n(2)) + "t+" + num2str(phi(2)) + ")";
x_2 = num2str(X(1)*r(1)) + "cos(" + num2str(w_n(1)) + "t+" + num2str(phi(1)) + ") + " + num2str(X(2)*r(2)) + "cos(" + num2str(w_n(2)) + "t+" + num2str(phi(2)) + ")";
This approach directly combines the values and strings using the + operator, eliminating the need for sprintf.
The num2str function is used to convert numeric values to strings.
Both approaches will produce the same result, but using string concatenation might be more readable and straightforward in this case.
For further reference, please refer these links to know more about ‘String concatenation’ and ‘num2str’
I hope this helps resolving the issue.