Drawing upon general, user-created mfiles and .mat files for the Answers forum RUN feature

1 view (last 30 days)
Thanks to brilliant advice from Ameer Hamza, I have found a way to draw upon URL-posted .mat files as input to the Matlab Answers forums' new Run feature (now in beta-testing at the time of this writing), e.g,
S=load(websave('tst', 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/414803/tst.mat'));
b=S.a+1
b = 2
I was wondering if the same technique (or a different one?) could be expanded, so as to draw upon user-created mfunctions, scripts, and classdef files as well. Also, what is the life cycle of files that are "websaved" into whatever disk space is used by the Run feature? Do they just sit in some folder on a Mathworks computer forever, or are they purged the very moment the running of the code is complete?
  1 Comment
Mario Malic
Mario Malic on 22 Nov 2020
There's also a similar bot that runs on MATLAB Discord channel, but it differs from the implementation on the documentation (you can open a MATLAB instance if you click on 'Try this example' button) website. On Discord server it looks like every user has its own workspace .mat file, that does stay there, until you run clear command. You can try who and dir to see if it's still left there.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 22 Nov 2020
Edited: Matt J on 22 Nov 2020
Here is a test of the technique using an attached mfunction.
websave('testfunction', 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/423253/testfunction.m');
out=testfunction(10)
out = 100
And OMG it worked!!!
  1 Comment
Matt J
Matt J on 22 Nov 2020
Edited: Matt J on 22 Nov 2020
Do classdef's work as well?
websave('myclass', 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/423293/myclass.m');
S=load(websave('tst', 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/414803/tst.mat'));
obj=myclass;
out=obj.mymethod(10)
out = 70
Yes, they do !!!!!!

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!