How do I use load to load a .m file?
54 views (last 30 days)
Show older comments
Trying to load a .m file into my code, however when I run the code I get the following error.
>> load('ssb_2016_connor.m')
Error using load
Number of columns on line 2 of ASCII file ssb_2016_connor.m must be the same as previous lines
I checked the path and its the correct path and the file name is spelled correctly. What am I doing wrong?
0 Comments
Answers (2)
Walter Roberson
on 28 Jan 2016
load() of a text file is only for files that are compatible with save -ASCII . Such files do permit comment lines with the usual % operator, but all other lines must be a rectangular array of numbers, the same number of numbers on every line. Such files represent a single 2D matrix.
What was your intention when you load() the .m file? Is it a script? If so then you use run() to invoke it, or just give its name. Is it a set of functions? If so then you can call upon the function whose name is the same as the name of the file, by giving that name.
If the .m file is a set of functions and you are trying to import all of the function definitions into your current code, then there is no way to do that, but sometimes people try something like that when they are looking for private functions
1 Comment
Angel Gonzalez
on 5 Dec 2019
Probably Williams was looking for the "run" command, as in my case. Thank you Walter
Star Strider
on 28 Jan 2016
The load function is for .mat (and a few other types) of files, not .m-files. You can treat .m-files as text files in some instances, but there is nothing in them to actually load.
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!