print multiple lines to textarea
显示 更早的评论
app.TextArea.Value=sprintf('Fourier Number of Terms:%d\n\nEquation:\ny=a0',n);
for i=1:n
txt='+a%d cos(%dx)+b%d sin(%dx)';app.TextArea.Value=(sprintf(txt,i,i,i,i));
end
app.TextArea.Value=sprintf('\nCoefficients:\na0=%.4f',a0);
for i=1:n; app.TextArea.Value=sprintf('\na%d=%.4f \nb%d=%.4f',i,a(i),i,b(i)) ;
end
app.TextArea.Value=sprintf('\n\nJ=%.4f \n\nR^2=%.4f \n\nRMSE=%.4f',j1,rsq1,RMSE1);
if i run this code it only prints last sprintf output, how do i print all

like this one
采纳的回答
更多回答(1 个)
Benjamin Thompson
2022-2-15
1 个投票
Can you combine the outputs of all your sprintf calls into a single string, and pass this to app.TextArea.Value? It is not clear what app.TextArea.Value from your code, but my guess is that every time you assign something new to app.TextArea.Value, the previous information is deleted.
>> S1 = sprintf("My first string has number %d\n", 3)
S1 =
"My first string has number 3
"
>> S2 = sprintf("My second string has name %s\n", "Billy")
S2 =
"My second string has name Billy
"
>> S3 = strcat(S1, S2)
S3 =
"My first string has number 3
My second string has name Billy
"
类别
在 帮助中心 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!