How to access a file in another directory
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Stephen23
le 30 Avr 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.
Réponse acceptée
Stephen23
le 30 Avr 2020
Modifié(e) : Stephen23
le 30 Avr 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Search Path dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!