How do I insert the output of a command as formatted text in a live script.
조회 수: 11 (최근 30일)
이전 댓글 표시
Say I have a code line in a live script that generates output.
disp(magic(4))
I'd like to be able to copy the ouput
16 2 3 1
5 11 10 8
9 7 6 12
4 14 15 1
and past it a formatted text (monospaced, aligned, single line spacing) into the text of the script.
How do I do that?
댓글 수: 4
dpb
2021년 1월 18일
I've never used live script so "I know nuthink!" but if you can generate the output, why not just store it to a variable?
Now about reformatting it into the script "I know nuthink!" other than what can do with normal i/o. Formatting is something else again; too old a dog to worry about pretty; we were glad when first were able to put away the old Remington for the IBM Selectric; then to have an editor at all was remarkable achievement. :)
Rik
2021년 3월 17일
Maybe formattedDisplayText (introduced in R2021a) is useful in this context. See this blog post for context.
채택된 답변
추가 답변 (2개)
Raynier Suresh
2021년 1월 21일
편집: Raynier Suresh
2021년 1월 21일
You can use the evalc to evaluate MATLAB expression and capture results.
results = evalc('magic(5)')
You can also refer the below link for more information.
댓글 수: 1
Rik
2021년 1월 21일
I'm not sure I would encourage people to use eval. Actually I am sure about my opinion. At the very least I would mention to be very careful.
K.
2021년 3월 17일
If I'm understanding your question correctly, the following might help. After running your live script, right click on the output and choose "Copy Output". Then paste it into a text (not code) area. If you don't have a line of text to paste it into, click the "Text" toolstrip button to insert a line of text first. For example:
If you'd then like to reduce the vertical spacing, you can do something like the other answer and convert it to a Code Example. Select the pasted text, go to the "INSERT" Toolstrip, and click the "Code Example" button:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!