How do I run a function I downloaded?
显示 更早的评论
So I downloaded this script nsumk to do some cool partition of integers for me: https://www.mathworks.com/matlabcentral/fileexchange/28340-nsumk
When i open it in matlab it appears in the editor window, I think it's like in the place where I would normally write scripts (once I get that advanced, haha!). Anyway, what do I have to do from here to get this functiln nsumk running in my command line?? I've tried typing in numk and stuff like that but can't get it to work.
If you can't tell, i'm a total scrub at this stuff, but i'm very interested!!
Simple explanations appreciated!! Peace out!!!!
回答(1 个)
Mario Malic
2020-9-18
编辑:Mario Malic
2020-9-18
Please see John's comment as it's important.
Place the function in your current folder and call it from command window, or in write it in script.
[m,x] = nsumk(n,k)
8 个评论
John D'Errico
2020-9-18
编辑:John D'Errico
2020-9-18
NO. Don't move the function around, putting it in your CURRENT folder. This is bad avice!
Instead, learn about the search path. You might, for example, have one directory wher you put ALL douwnloaded functions. Put that directory on your search path. And don't forget to save your search path.
In the case of complete toolboxes, you put them in their own directories. also on the search path.
help addpath
help pathtool
help savepath
Why don't you want to move functions around?
Because if you do, then every time you move to a different directory, you need to move all of those functions around, into the new directory.
Once you have your new function in their own directories on the search path, you can now use them from any location, as MATLAB will always know they exist.
Finally, when you upgrade to a new MATLAB release, you can use my export_search_path utility, found on the file echange for download. It allows you to directly export the current search path to a file on your drive. Then open the new MATLAB release, and use the function import_search_path. It will recreate the entire search path from your previous release, but in the new release.
Learn about the search path. Your coding experience will be greatly improved for doing so.
Mario Malic
2020-9-18
编辑:Mario Malic
2020-9-18
I agree with everything what you said.
What I ment by current folder is that, user who writes code, one would create a folder, let's say on 'Desktop\MATLAB_Work\Project1\' and place his script there and set it as a current folder. Within it, one could place functions in or have a separate folder for the functions and addpath, as you mentioned.
Michael Vaughan
2020-9-19
Michael Vaughan
2020-9-19
Walter Roberson
2020-9-19
You need to either have defined n and k already as variables, or else pass in particular numeric values.
n = 7; k = 4;
[m, x] = nsumk(n, k);
or
[m, x] = nsumk(7, 4);
Michael Vaughan
2020-9-19
编辑:Michael Vaughan
2020-9-19
Michael Vaughan
2020-9-19
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!