Effacer les filtres
Effacer les filtres

Assignment error with dir

2 vues (au cours des 30 derniers jours)
B.M.
B.M. le 18 Fév 2014
Modifié(e) : per isakson le 18 Fév 2014
I hate to ask what seems like such an idiotic question, but I can't just run my script because it hiccups at this step:
d=dir(Dir);
??? d=dir(Dir);
|
Error: The expression to the left of the equals
sign is not a valid target for an assignment.
I have tried changing it in several ways, but still get the assignment error. This is frustrating because I need to be able to access within the structure in the next step:
isub = [d(:).isdir]; % returns logical vector corresponding to subfolders
Date = {d(isub).name}'; %pulls out names of subfolders
Strangely, if I highlight it in the Editor and run it alone (evaluate selection/F9), it works. Can anyone suggest what might be going on? Very much appreciated.
  1 commentaire
per isakson
per isakson le 18 Fév 2014
Modifié(e) : per isakson le 18 Fév 2014
  • which dir -all
  • restart Matlab
I need to try something like
>> d+1 = dir('*.m');
d+1 = dir('*.m');
|
Error: The expression to the left of the equals sign is not a valid
target for an assignment.
to see that error message. "???" does that indicate an old release of Matlab?

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 18 Fév 2014
At the command line, give the command
dbstop if error
and run the code. When it stops for the error, give the command
whos d
and see what it indicates
To cross-check: you have deleted the entire line and re-typed it, just in case there is a special character there?
  1 commentaire
B.M.
B.M. le 18 Fév 2014
Hi Walter,
I tried dbstop and couldn't do 'whos d' because d couldn't be written/assigned. Only sometimes when I run that one line (not the whole section) with F9, it will work, in which case whos d returns what I want it to ( d 95x1 60897 struct ).
I tried deleting and retyping, and trying other variable names. No luck. I just don't understand it!

Connectez-vous pour commenter.

Catégories

En savoir plus sur File Operations 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!

Translated by