How to specify path in MATLAB?

8 Ansichten (letzte 30 Tage)
Maura
Maura am 2 Nov. 2018
Kommentiert: Maura am 6 Nov. 2018
Hello, I'm having a problem with pathing in MATLAB. To path to the folder with the data for the script I use;
folder = '//uofa/users$/users4/a1225844/MATLAB/Stripflow/Col1/Col_0/'
The following errors pop up;
Error using fgetl
Too many output arguments.
Error in fgetl (line 34)
[tline,lt] = fgetl(fid);
Error in read_singlestack_input_v1_0 (line 12)
dat_line = fgetl(fid);)
For this script these errors always occur when the path is incorrect. Currently, the only folder in Col1 is Col_0.
Since it was running on a network location, I tried copying files onto the C: drive and running it from there. I tried changing folders on the search path by going to the Home tab-->Environment section-->Set path-->Add folder-->//uofa/users$/users4/a1225844/MATLAB/Stripflow/Col1/Col_0/-->Save. I tried eliminating the $ in users$, this made MATLAB 'think' for a minute before giving the same errors. I tried using double quotes rather than single quotes, putting parentheses around it, and using the backwards slash rather than the forwards slash. For each one, the same error messages popped up.
I just started learning MATLAB, so sorry if this is a stupid question.
  2 Kommentare
Stephen23
Stephen23 am 2 Nov. 2018
Note that this line has extra character that will cause an error:
dat_line = fgetl(fid);)
^ ouch!
Maura
Maura am 5 Nov. 2018
Whoops! That was a error I made when putting the errors up. I checked the code and it wasn't there. Sorry about that.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 2 Nov. 2018
Bearbeitet: Stephen23 am 2 Nov. 2018
fgetl only has one output argument, so calling it with two will throw an error.
However that error message indices that you see to have created a function named fgetl, which is shadowing the inbuilt fgetl:
Error in fgetl (line 34)
[tline,lt] = fgetl(fid);
Check this command:
which fgetl -all
and rename any of your own functions/scripts that use that name. Only the inbuilt commands should use inbuilt function names.
  7 Kommentare
Walter Roberson
Walter Roberson am 6 Nov. 2018
I checked my R2013a copy and in it, line 34 (same line number as you quoted) has
[tline,lt] = fgets(fid);
Whereas your error message was for
[tline,lt] = fgetl(fid);
This is a significant difference as it would cause fgetl to call itself recursively. If it did not crash due to reaching recursion limit, if somehow fgetl managed to return once, then it would immediately encounter the problem that fgetl only returns one output, and it would be an error to assign that one output to two variables.
You should have a look at the modification dates of files in C:\Program Files\MATLAB\R2013a\toolbox\matlab\iofun and see if fgetl.m was modified notably after the others. If it was, then maybe somehow someone accidentally corrupted it during debugging something and you can just modify it to call fgets instead of fgetl. But if the date for fgetl is about the same as for the other files there, then I would recommend reinstalling MATLAB as there could be other corruptions lurking around.
Maura
Maura am 6 Nov. 2018
Thank you so much!!! Fgetl.m was modified several years after the others, I modified it to call fgets and it's working now!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Produkte


Version

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by