How to access a file in another directory
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Stephen23
il 30 Apr 2020
"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.
Risposta accettata
Stephen23
il 30 Apr 2020
Modificato: Stephen23
il 30 Apr 2020
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Search Path in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!