外部.mファイルで定義される関数の呼び出し
조회 수: 126 (최근 30일)
이전 댓글 표시
.mファイルで定義している関数を別ファイルで実行する方法について質問です。
①の関数処理中に②の関数を上手く呼び出すことができません。
どのようにすれば上手く呼び出すことができるでしょうか?
①Production Serverコンパイラ―でコンパイルした関数
②sampleFunc.m
●コード
①で②を呼び出すコードは
sampleFunction = @sampleFunc;
sampleOut = sampleFunction(x);
②の関数は
function sampleOut = sampleFunc(x)
sampleOut = x;
end
●実現したい処理フロー
MathWorks.MATLAB.ProductionServer.ClientでProduction Serverにある①を呼び出し(ここはOK)
⇓
①から②を呼び出し(ここがNG)
●試したこと
・①と同じ階層に②を配置
・①と同じ階層に②をProduction Serverコンパイラで作成したctfファイルを配置
・table2cell.mなどの標準関数と同じ階層に②を配置
⇒ いずれも『関数 'sampleFunction' (タイプ'****' の入力引数)が未定義です。』のエラー
****の部分は入力として渡した変数の型が入ります。(table,cell,stringなど、どのパターンでもエラー)
댓글 수: 0
채택된 답변
Kojiro Saito
2022년 10월 5일
sampleFunc.mがProduction Serverコンパイラの「アーカイブの実行に必要な追加ファイル」に入っていれば、①から②を呼び出すのができるようになります。
①と②が同じ階層か、②がMATLABのpathコマンドで表示される検索パスのフォルダにあれば、コンパイル時に自動的に取り込まれます。
WindowsのコマンドプロンプトからcURLで呼び出し。
curl -v -H "Accept: application/json" -H "Content-type: application/json" http://localhost:9910/myfunc/myfunc -d "{\"nargout\":1, \"rhs\":[100], \"outputFormat\":{\"mode\": \"large\",\"nanInfFormat\": \"object\"}}"
実行結果
* Trying 127.0.0.1:9910...
* Connected to localhost (127.0.0.1) port 9910 (#0)
> POST /myfunc/myfunc HTTP/1.1
> Host: localhost:9910
> User-Agent: curl/7.83.1
> Accept: application/json
> Content-type: application/json
> Content-Length: 85
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 59
< Connection: Keep-Alive
<
{"lhs":[{"mwdata":[100],"mwsize":[1,1],"mwtype":"double"}]}* Connection #0 to host localhost left intact
「MathWorks.MATLAB.ProductionServer.ClientでProduction Serverにある①を呼び出し」でMPSクライアント側でどのようにMPS呼び出しの処理を書いていますでしょうか?
また、デバッグ用にProduction Serverコンパイラで「クライアントのテスト」ボタンをクリックして、「CORSを有効にする」にチェックを入れて、「起動」を押して、MATLAB上でMPSの疑似インスタンスを開始してください。
エディターで①のmファイル(ここではmyfunc.m)を開き、sampleFuncを呼び出す前(ここでは2行目)にブレークポイントを張り、MPSの関数をクライアントから呼び出してみてください。xにどのデータ型が渡っているのか確認できます。
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Installation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!