How can I programmatically open the results of a command in a new window without setting it to a variable?

12 ビュー (過去 30 日間)
As a basic example, I want to type in something like:
function(2+2)
... and the output would open a new window as if I'm opening the "ans" variable to display "4" as the answer.

採用された回答

Image Analyst
Image Analyst 2022 年 7 月 25 日
If you're using windows you can use fprintf() to write whatever you want to a text file, then use winopen() to open the file in a new window.
result = f(2,2); % Do some computation and get a result.
fid = open('answer.txt', 'wt'); % Open a file for writing.
fprintf('Result = %f.\n', result); % Write whatever you want.
fclose(fid); % Close the file.
winopen('answer.txt'); % Open the file in notepad or the default text handling program.
Is that what you mean?
  4 件のコメント
em7
em7 2022 年 7 月 26 日
I know it's an odd question.
It was mainly for accessing data sets for analysis amongst 200k+ sets just for temporary display.
Typically, I set it to a variable and open using Ctrl + D and then go back and delete the variable to avoid workspace clutter since there exists MANY variables.
Thank you for the input.
Image Analyst
Image Analyst 2022 年 7 月 26 日
You know you can double click on a variable in the workspace and it opens up in the variable editor window. Maybe that will suffice.

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

その他の回答 (1 件)

Les Beckham
Les Beckham 2022 年 7 月 25 日
編集済み: Les Beckham 2022 年 7 月 25 日
I can only think of a way to do this in two steps rather than one.
result = 2 + 2;
openvar('result');
Error using matlab.internal.lang.capability.Capability.require
Support for user input is required, which is not available on this platform.

Error in openvar (line 98)
Capability.require(Capability.InteractiveCommandLine);
This should work in desktop Matlab (you should not get the error that is showing here in the forum using Matlab online).
If you insist on not "setting it to a variable":
2 + 2
openvar ans

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by