How to pass filepath to MATLAB executable

Hi All,
I have created a executable using the application complier.
The function requires the input file path
function main(filepath)
I am not sure how to pass the file path as an input argument to the executable generated using the about funciton.
I tried
!main 'I:\project\task'
but this is not working.
Suggestions will be really helpful.

2 件のコメント

Jan
Jan 2023 年 2 月 27 日
"This is no working" is too lean to explain, what happens. Prefer to mention, what you observe. This helps to solve your problem.
Deepa Maheshvare M.
Deepa Maheshvare M. 2023 年 2 月 27 日
編集済み: Deepa Maheshvare M. 2023 年 2 月 27 日
Sorry about missing out on the error details.
function main(TASK_DIR)
tbl = readtable(fullfile(TASK_DIR,'input.xlsx'));
I see the following error message
>> !main char(task_dir)
ans =
'char(task_dir)'
....read data
Error using readtable (line 318)
Unable to find or open 'char(task_dir)\input.xlsx'. Check the path and filename or file permissions.

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

 採用された回答

Rik
Rik 2023 年 2 月 27 日
編集済み: Rik 2023 年 2 月 27 日

2 投票

You're using Matlab syntax to define a char vector, but that is something that will happen automatically.
You can experiment with this tester function:
function main(varargin)
for n=1:nargin
fprintf('input number %d has class %s and contains this:\n',n,class(varargin{n}))
disp(varargin{n})
fprintf('\n')
end
end
To avoid syntax error caused by DOS itself you should consider
!main "I:\project\task"
You can test the effect quickly by using ECHO so you get immediate feedback about any syntax issues.
Edit after your comment to Jan:
You probably want this:
[status,response]=dos(['main ' taskdir]);
That will send the char contained in taskdir as the argument to the function main.

4 件のコメント

Deepa Maheshvare M.
Deepa Maheshvare M. 2023 年 2 月 27 日
I'm sorry, I am a bit confused
Could you please tell me how to run the executable from MATLAB's command window?
I do
!main
on the command window to run the main.exe file when I don't have to pass input arguments. Now, I am not sure how to pass the filepath.
Rik
Rik 2023 年 2 月 27 日
編集済み: Rik 2023 年 2 月 27 日
Did you try any of my suggestions? I gave three, you don't appear to have tried any of them.
Deepa Maheshvare M.
Deepa Maheshvare M. 2023 年 2 月 28 日
I had tried the last option which didn't work for me.
The second suggestion works great! Thanks a lot.
Rik
Rik 2023 年 2 月 28 日
Glad you found a solution, happy to help.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeC Shared Library Integration についてさらに検索

製品

リリース

R2021a

質問済み:

2023 年 2 月 27 日

コメント済み:

Rik
2023 年 2 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by