compiled app can not run mfiles in a folder

1 view (last 30 days)
Hi Al
Due to app designer limitations with saving a figure (version 2017b). I came up with the idea to write the savefig command in an mfile via app(create the mfile via my application) and save that mfile in my desired directory and run it via my app ( actually with matlab) by calling it from my application.
this was working untill I had my app open in MATLAB and not compiled because it was actually MATLAB who was running that mfile. Now after compiling, I noticed this trick does not work ! Any advices ? I have tried the other tricks like creating invisible fig un UIaxes but it did not work. at least for me
I do this in my app :
txt=['saveas(f,filename,''jpg'')'];
% edit file.m
FID=fopen('filem.txt','w');
fprintf(FID, '%s', txt);
fclose(FID);
% Rename File to Create M File
movefile('filem.txt','filem.m', 'f')
filem
I am not sure if doing so would solve the problem :
run('filem.m')
  3 Comments
farzad
farzad on 2 Apr 2020
f is :
f = figure('visible', 'off');
I have tried another answer where it was suggeting to use hidden UIAXES and it did not work. are you sure the above answer will work after compiliing ?
I have a UIAxes panel in my app but it's for another purpose. will these two interfere ?I have also rainflow function to save

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Apr 2020
You will never be able to generate a function or a script inside a compiled app and run it inside the compiled app.
Never
This is a deliberate design decision. You are permitted to compile code and run it without a MATLAB license under the restriction that the code to be executed cannot be changed. If you need the code to be executed to be changed, then you need a full MATLAB license to run it.
  25 Comments
Adam Danz
Adam Danz on 3 Apr 2020
As you found, figure('visible', 'off') is the reason you couldn't see the figure. This problem has nothing to do with UIAxes; it has nothing to do with copying axes. A mini lesson to be learned here is to take time to understand the problem before trying random solutions.
"If I had only one hour to save the world, I would spend fifty-five minutes defining the problem, and only five minutes finding the solution." -Albert Einstein
First, get rid of the copyUIAxes stuff... it's completely irrelevant.
Second, to save your figure, use your figure handle, f:
savefig(f,'myFigure.fig')
farzad
farzad on 4 Apr 2020
thank you very much it worked fine !

Sign in to comment.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!