How to display values with formatting, converting numbers to strings

T
taranjeetisingh · Aug 18, 2020 · 1.9K views
Question
if size(cost,1) == 2 A = (4*Pdt*cost(1,3)*cost(2,3)) + 2*(cost(1,2)*cost(2,3))+(cost(1,3)*cost(2,2)); B = 2*(cost(2,3)+cost(1,3)); lambda = num2str(A ./ B); set(handles.answer1_staticText,'String', lambda); P1 = (lambda - cost(1,2))./(2*cost(1,3)); P2 = (lambda - cost(2,2))./(2*cost(2,3)); PT = mat2str(P1 + P2); set(handles.answer2_staticText,'String', PT); guidata(hObject, handles); end From the coding above, the answer become like this :   [11.75 11.25 11.25 11.75 10.75 11.5 12.75 12.75 13] My question is I want to display my answer at the static text box like this:   P1 = (%answer for P1) P2 = (%answer for P2) P TOTAL = (%answer for PT) Can anyone help me with the coding?
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Nov 20, 2025

You can build the multiline text, for example:

 

{['P1 =' string1],['P2 =' string2],['P3 =' string3]}
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!