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 Aug 24, 2026

You can build the multiline text, for example:

 

{['P1 =' string1],['P2 =' string2],['P3 =' string3]}
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!