MATLAB sometimes thinks the keyword "ans" refers to a a file

조회 수: 1 (최근 30일)
Lucas Di Pietro
Lucas Di Pietro 2024년 2월 16일
댓글: Lucas Di Pietro 2024년 2월 16일
When I try to use certain functions on the keyword ans in the Command Window I'm getting the following error, along with some example context:
theta3D =
(5*cos((pi*theta2)/180))/(16*(1 - (25*sin((theta2*pi)/180)^2)/256)^(1/2))
>> latex(ans)
Execution of script ans as a function is not supported:
C:\Program Files\MATLAB\R2023a\toolbox\matlab\lang\ans.m
It appears that MATLAB is trying to reference a file but I'm not sure why this has started happening recently. The folder \toolbox\matlab\lang\ is in the path when I use the path keyword. I don't want to delete the file since it's part of the program files, but is there a way to override this so I can refer to ans in the Command Window again?

채택된 답변

Steven Lord
Steven Lord 2024년 2월 16일
If there's no variable named ans in the workspace, MATLAB would try to call the ans.m script file that contains the help text related to using ans.
which -all ans
/MATLAB/toolbox/matlab/lang/ans.m
type ans.m
%ANS Most recent answer. % ANS is the variable created automatically when expressions % are not assigned to anything else. ANSwer. % Copyright 1984-2005 The MathWorks, Inc. % Built-in function.
But calling it with an output (as you did by calling it to create the input to the latex function or as I'm doing below by calling it to create the first input to the plus function) won't work.
ans+1
Execution of script ans as a function is not supported:
/MATLAB/toolbox/matlab/lang/ans.m
For what you wrote, the symbolic expression is stored in a variable named theta3D. So you'd want to call latex on that symbolic expression, not ans.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace 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