フィルターのクリア

How to access a file in another directory

9 ビュー (過去 30 日間)
bruno mansur
bruno mansur 2020 年 4 月 30 日
編集済み: Stephen23 2020 年 4 月 30 日
Hi there!
I'm writting a script located in the driver 'E:\' and I want it to access a file in 'C:\'.
When try to read the file I receive this message:
>> ls C:\Program Files\MATLAB\R2018a\toolbox
Error using ls (line 60)
Too many input arguments.
I've also tried using '/' before 'Files' and received the same error message:
>> ls C:\Program/ Files\MATLAB\R2018a\toolbox
Error using ls (line 60)
Too many input arguments.
Why is it happening and how can I overcome this problem?
Thanks in advance!
  1 件のコメント
Stephen23
Stephen23 2020 年 4 月 30 日
"C:\Program Files\MATLAB\R2018a\toolbox"
Accessing files directly inside any application's installation folder is a very dubious idea. Most likely you should just set the MATLAB Search Path and rely on MATLAB to locate the files.

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

採用された回答

Stephen23
Stephen23 2020 年 4 月 30 日
編集済み: Stephen23 2020 年 4 月 30 日
The problem is that you are using command syntax (an unfortunate remnant of MATLAB's venerable origins):
With command syntax every space separates one variable. Look at your code and find the spaces:
ls C:\Program Files\MATLAB\R2018a\toolbox
% ^ ^ two spaces!
So if we were to write your command syntax as a normal function call, it would look like this:
ls('C:\Program','Files\MATLAB\R2018a\toolbox')
% ^^^^^^^^^^^^ 1st input
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2nd input
So how many inputs are you calling ls with? (hint: two)
The best solution is to forget about (awful, outdated, ugly) command syntax and always use function syntax:
ls('C:\Program Files\MATLAB\R2018a\toolbox')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by