How to call another matlab scripts which are in the same directory?

23 ビュー (過去 30 日間)
Mr. 206
Mr. 206 2019 年 2 月 11 日
コメント済み: Image Analyst 2019 年 2 月 11 日
I have one "Main_File.m" which i am running from a bash script. Inside the "Main_File.m", I am calling two of the matlab scripts (primary_script.m, secondary_script.m) which are in the same directory. But the bash script generating an error like "error: 'primary_script' undefined near line 64 column 5".
But if I run the "Main_File.m" through MATLAB it is compiling and generating results without any error.
How can i solve this issue?
  3 件のコメント
Mr. 206
Mr. 206 2019 年 2 月 11 日
  1. I have to call the Matlab script in the bash script.
  2. I am sure bash can run matlab scripts pritty well.
  3. It is not possible in my case to write function.
Rik
Rik 2019 年 2 月 11 日
Bash cannot run Matlab scripts. What you can do is call Matlab from the command line, or compile your code to executable code. If you do neither, I would be very interested to know your exact syntax.
Why do you think it is impossible in your case to turn your script into a function?
As for your error, I suspect this has to do with the current folder being some unexpected location, which would cause this issue.

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2019 年 2 月 11 日
Just put in the name of the scripts you want to call in "Main_File.m".
Have "Main_File.m" look like this:
% some code first, perhaps...
% Then call the first script
primary_script.m
% Maybe more code, then call the second script
secondary_script
  2 件のコメント
Mr. 206
Mr. 206 2019 年 2 月 11 日
I also tried that. Still same kind of error.
Image Analyst
Image Analyst 2019 年 2 月 11 日
Then the primary_script is not on the search path. What does this show:
>> which -all primary_script

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by