How To Read Procedure From File?
古いコメントを表示
I've written a procedure and saved it in a file. It passes the syntax text. Now I want to be able to call that procedure from Matlab.
>> run( vecrot3 )
Attempt to execute SCRIPT vecrot3 as a function:
C:\Users\Lenovo\Documents\Matlab Scripts\vecrot3.m
Matlab is correct in that this is what I am trying to do. What's the magic word?
5 件のコメント
dpb
2018 年 12 月 23 日
The argument needs to be a string, not the function; ML is trying to execute it first and then pass its result to run.
You don't need run at all, just write
vecrot3
to execute the script.
If you really, really, wanted to use run for some unknown reason (about only real one is if it isn't on the path, but that doesn't seem to be the case or you'd have gotten the "no such function" error instead, that syntax would be
run('vecrot3')
to pass the name.
Patrick Powers
2018 年 12 月 23 日
編集済み: madhan ravi
2018 年 12 月 23 日
madhan ravi
2018 年 12 月 23 日
編集済み: madhan ravi
2018 年 12 月 23 日
that doesn‘t look like a valid Matlab syntax , upload the files to test
Patrick Powers
2018 年 12 月 23 日
Stephen23
2018 年 12 月 23 日
"Care to share just why you think the syntax is wrong?"
For a start, this line:
vecrot3 := proc( v, th )
The MathWorks makes many different tools, e.g. MATLAB, Simulink, etc.. Some of those tools can work together, but they are still separate tools. That line shows that you are reading/copying some MuPad code. If you want to use the MuPad tool, then that is perfect.
If you think that you are writing MATLAB code, then this will not help you, in exactly the same way that reading Java documentation will not help you to write Haskell code.
You need to be clear what tools you are using and follow the appropriate documentation.
The best place to learn basic MATLAB concepts and learn what MATLAB code looks like, is in the introductory tutorials:
回答 (1 件)
madhan ravi
2018 年 12 月 23 日
編集済み: madhan ravi
2018 年 12 月 23 日
ADDENDUM to dpb's comment :
"Care to share just why you think the syntax is wrong?"
See https://www.mathworks.com/matlabcentral/answers/436962-trying-to-put-code-in-a-file#answer_353634
v = 1:3; % an example
th = pi;
Result = vecrot3( v, th ) % function call
function Result = vecrot3( v, th ) % function definition
M = [ cos(th) -sin(th) 0 ;
sin(th) cos(th) 0 ;
0 0 1 ];
Result = v * M ;
end
Note: Beware MUPAD is going to be removed in the future release so get used to MATLAB as soon as possible.
カテゴリ
ヘルプ センター および File Exchange で Get Started with MuPAD についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!