Call a pcode file (of a character array) within a MatLab script
2 ビュー (過去 30 日間)
古いコメントを表示
Im trying to call a pcode file whose contents are a character array as part of a MatLab .m file script and compare the contents of the pcode file to a non pcode file whose contents are also a character array. If I call the pcode file in the command window it displays the contents and puts it in the workspace within the variable "ans". However when I call the pcode file in the .m file script it does not appear to actually run the pcode file and the "ans" in the workspace is "0". I am calling it by just using the filename of the pcode without the ".p" in the MatLab script.
0 件のコメント
採用された回答
Walter Roberson
2023 年 2 月 17 日
This is unusual, but possible. Code can examine the call-stack depth to determine whether it was called inside a function or script, or from the command line.
It would be more common to have code that produces different results depending on whether it called in an output context or not. For example,
fprintf('hello')
ans
0 + fprintf('hello')
ans
What is happening here is that fprintf() is examining nargout() and only generating return values in the case that nargout == 1.
Or consider the difference between
plot(1:5)
ans
plot noticed that no output was requested and so did not emit any output
h = plot(1:5)
plot() noticed that output was requested and returned the line() handles.
So code can pay attention to whether output is requested or not.
Anyhow... I would suggest experimenting with using evalc() and see what you get in the output variable.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!