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!