Call a pcode file (of a character array) within a MatLab script
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
mark hoffman
le 17 Fév 2023
Commenté : mark hoffman
le 18 Fév 2023
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 commentaires
Réponse acceptée
Walter Roberson
le 17 Fév 2023
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Whos dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!