Jonas Stein
Jonas Stein

Reputation: 7043

Why does Matlab only accept a small set of characters in script filenames?

Matlab requires that script files are limited to only 63 characters

>> namelengthmax
ans =
    63

and these 63 characters must be out of a small characterset without - and others.

Why does Matlab limit the filenames and is there a workaround?

Upvotes: 2

Views: 128

Answers (1)

Hoki
Hoki

Reputation: 11812

The comment from beaker answers part of your question. Because they can also be funtion names, you are restricted in the character they can incorporate.

For example, if you had a file (function) named foot-ball.m, when you call it in an instruction, Matlab couldn't differentiate between:

a = foot-ball ;

where you mean to call the result of a function named foot-ball.m (actually impossible)

or

a = foot-ball ;

assigning to variable "a" the result of function foot.m minus the result of function ball.m

As to the maximum length, there are no workaround (yet) to my knowledge (until Matlab lift the restriction).

Remember that your operating system also has a limit to the length of file (and full path). On windows it is 256+4 characters. So I guess limiting a file name length to 63 is just to allow for 193 characters of full path. This can be quickly reached, faster than we think.

If your filename was 255 character long, you would have no other choice than to put it directly into c:\ or the operating system couldn't access it (so Matlab couldn't call it obviously).

Use the instruction len = namelengthmax to get the actual maximum length on your system. You can read more about it in specify file names.

or also read a similar problem from another user: Extending the maximum length of MATLAB function names. Note that this user couldn't bypass the length limit, he had to find another way to fit all the information he wanted into the maximum file name.

Upvotes: 3

Related Questions