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

105 visualizzazioni (ultimi 30 giorni)
William Mills
William Mills il 28 Gen 2016
Commentato: Angel Gonzalez il 5 Dic 2019
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?

Risposte (2)

Walter Roberson
Walter Roberson il 28 Gen 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 Commento
Angel Gonzalez
Angel Gonzalez il 5 Dic 2019
Probably Williams was looking for the "run" command, as in my case. Thank you Walter

Accedi per commentare.


Star Strider
Star Strider il 28 Gen 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.

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by