How to specify path in MATLAB?

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 Comments

Note that this line has extra character that will cause an error:
dat_line = fgetl(fid);)
^ ouch!
Whoops! That was a error I made when putting the errors up. I checked the code and it wasn't there. Sorry about that.

Sign in to comment.

 Accepted Answer

Stephen23
Stephen23 on 2 Nov 2018
Edited: Stephen23 on 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 Comments

Thanks for the answer and breaking things down. I actually didn't write the script, someone else who's an expert in MATLAB did. We have used this exact script many times in the lab, and always when the path is incorrect these errors pop up. My PI ran the exact same script a week ago and it ran fine. I don't know what I'm doing wrong and neither does he. I'm using a different MATLAB from what we use back in the lab since I'm doing research abroad right now.
Whichever fgetl is shadowing the better fgetl probably has a bug for the case where the file identifier is non positive as would be the case when the fopen before it has failed.
Note: fgetl is a MATLAB function that has a very similar line with the same two outputs, but the right hand side is fgets not fgetl. Is it possible that you mistyped the error when you posted it?
I double checked the error, other than the extra ) everything is the same. Also I noticed that each time I run it, the fid= in the workshop increases by 1. When I use a dummy folder fid=-1.
On the system with the problem, set up to the right directory and then show us
which -all fgetl
Note: it sounds like the code is failing to fclose(fid), even if only in the case of an error.
Okay, here's what comes up;
C:\Program Files\MATLAB\R2013a\toolbox\matlab\iofun\fgetl.m
C:\Program Files\MATLAB\R2013a\toolbox\matlab\iofun\@serial\fgetl.m % serial method
C:\Program Files\MATLAB\R2013a\toolbox\instrument\instrument\@udp\fgetl.m % udp method
C:\Program Files\MATLAB\R2013a\toolbox\shared\instrument\@icinterface\fgetl.m % icinterface method
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.
Thank you so much!!! Fgetl.m was modified several years after the others, I modified it to call fgets and it's working now!

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2013a

Asked:

on 2 Nov 2018

Commented:

on 6 Nov 2018

Community Treasure Hunt

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

Start Hunting!