How do I use load to load a .m file?

56 次查看(过去 30 天)
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?

回答(2 个)

Walter Roberson
Walter Roberson 2016-1-28
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 个评论
Angel Gonzalez
Angel Gonzalez 2019-12-5
Probably Williams was looking for the "run" command, as in my case. Thank you Walter

请先登录,再进行评论。


Star Strider
Star Strider 2016-1-28
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.

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by