How to call a value from the command window to the editor window

20 ビュー (過去 30 日間)
Io7
Io7 2021 年 11 月 24 日
コメント済み: Jan 2021 年 11 月 24 日
MATLAB
How to call a value from the command window to the editor window, while the value does not appear on the workspace. the value appears after using a .p code!
For example:
Editor:
A = TSystemT(B,C) % <------- this is calling the .p code called TSystemT
Command Window:
The value is 123 <---- this appears on the command window when running A = TSystemT(B,C)
Now I want to somehow import the value shown on the command window which is "123" to the Editor
like D = the value is shown on the command window

回答 (2 件)

Jan
Jan 2021 年 11 月 24 日
Is it really a small integer? Then simply type "123". If it is a much more complicated nested struct, please explain this. It matters, which kind of variable you want to import as code.
What about inserting this line in the function:
D = TSystemT(B,C);
  2 件のコメント
Io7
Io7 2021 年 11 月 24 日
The thing is that I use a p-code. and when I call it I get like many texts on the command window and nothing on the workspace except the A value which is something else:
for example when I run: A = TSystemT(B,C)
on the command window I get :
The value of M = 10
The value of N = 5
The value of S = 123
so I was looking to see if there is a way to call the S value from the command window to use it on the editor:
Jan
Jan 2021 年 11 月 24 日
Do you want to do this once or frequently? For doing this once, copy&paste is the simple solution. To do this automatically, there are different options:
  1. evalc (see Stephen's answer). Then you have to parse the output.
  2. You can move the P-file to a specific folder and shadow the built-in functions disp and fprintf. The user-defined versions have to store the output in a persistent variable and flush it for a specific input later on, if they are called from the function. This is a very complicated way to obtain the data. It would be much easier to ask the author of the P-function to create a version with a smarter output of the results.

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


Stephen23
Stephen23 2021 年 11 月 24 日
編集済み: Stephen23 2021 年 11 月 24 日
Ugh, P-Files.
and then parsing the string that it returns,e.g. using regular expressions. Not very pretty, but it might work:
[txt,A] = evalc('TSystemT(B,C)')

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by