Separating sgtitle(sprintf()) into three lines of code

sgtitle(["ECE 202 Exercise M7: Current, voltage, and power absorbed";...
sprintf("by a charging Inductor($V_0$ = $%g$V, $R$ = $%g\\Omega$, $L$ = $%g$mH)", V0, R, L)],'Fontsize', 18)
This is my code for a subplot title. I want the code the to stay the same, but I need to make the code spill onto another line after " \\Omega$, "
The line of code is too long for the line its on, when I try to separate within the " " of the sprintf text my code doesn't work. I tried adding [ ] this also didn't work.

回答 (1 件)

Simon Chan
Simon Chan 2022 年 1 月 27 日

0 投票

Try the following to see whether this i swhat you want:
sgtitle(["ECE 202 Exercise M7: Current, voltage, and power absorbed";...
sprintf("by a charging Inductor($V_0$ = $%g$V, $R$ = $%g\\Omega$,\n $L$ = $%g$mH)", V0, R, L)],'Fontsize', 18)

3 件のコメント

Jasilva
Jasilva 2022 年 1 月 27 日
No, I don't want the output to remain the same as my current code, but I want the script to continue on another line. I want the code to look something like this:
sgtitle(["ECE 202 Exercise M7: Current, voltage, and power absorbed";...
sprintf("by a charging Inductor($V_0$ = $%g$V, $R$ = $%g\\Omega$,
$L$ = $%g$mH)", V0, R, L)],'Fontsize', 18)
But any way that I try to put the script on on a new line using a " ; " or more parenthesis' or brackets, the output doesn't work. I only want to change the format of the code, not the output.
Jasilva
Jasilva 2022 年 1 月 27 日
Simon Chan
Simon Chan 2022 年 1 月 27 日
I can think of the following workaround by using function join.
sgtitle(["ECE 202 Exercise M7: Current, voltage, and power absorbed";...
sprintf(join(["by a charging Inductor($V_0$ = $%g$V, $R$ = $%g\\Omega$,",...
"$L$ = $%g$mH)"]), V0, R, L)],'Fontsize', 18)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

リリース

R2020b

質問済み:

2022 年 1 月 27 日

コメント済み:

2022 年 1 月 27 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by