Pack several files in one .p file

7 次查看(过去 30 天)
Hi,
The question was asked in 2009 in Matlab newsreader. http://www.mathworks.com/matlabcentral/newsreader/view_thread/260237
I have a program which uses several .m files (in fact it is a GUI). I know I can protect these files using PCODE command (and then obtaining a .p file per each .m file), but, can I "embed" or pack all this files in just one? Then I will only need to handle a .p file for the whole program. When executing this file in matlab the program will run.
anybody knows how to get over this !

采纳的回答

Titus Edelhofer
Titus Edelhofer 2012-1-4
Hi,
what you can try (it works, as long as you don't have subfunctions somewhere with the same name as .m files): append all .m files at the bottom of the main GUI. This way all .m files become subfunctions of your GUI. Make sure though that you consistently use the "end" for end of function (i.e., either put for all functions and all .m files an end at the end or for none of them).
You can try this with one function first: copy the content to the end of your GUI (and delete the original .m). Run the code in MATLAB to test.
Edited: here some pseudocode
fidMain = fopen('maingui.m', 'a');
files = dir('*.m');
% remove maingui from list:
files(strcmp({files.name}, 'maingui.m')) = [];
for i=1:length(files)
fid = fopen(files(i).name, 'rt');
content = fread(fid, '*uchar');
fclose(fid);
fprintf(fidMain, '%%%file %s\n', files(i).name);
fwrite(fidMain, content, 'uchar');
end
fclose(fidMain);
Titus
  6 个评论
Sukuchha
Sukuchha 2012-1-4
Thank you both Titus and Sean. Titus thanks for the Pseudo code, it helped a lot ! It worked fine all the m files are now in my GUI.m file.
But when i ran pcode GUI.m, i ran into a problem. I am dealing here with a multispectral data which is lets say (5000X5000x4). The file cannot be open at once therefor i have wrote a MyAdapter following an example at http://goo.gl/8v88l that will open my files using blockproc.
Now the problem is, the Adapter requires definition of a class with a line like classdef MyAdapter < ImageAdapter, but now when making a pcode, there is an error which says
Illegal use of reserved keyword "classdef".
Is there a work around ?
Walter Roberson
Walter Roberson 2012-1-4
No, classdef must be in separate files.

请先登录,再进行评论。

更多回答(1 个)

Sukuchha
Sukuchha 2012-1-4
So this is what i did, and it works wonderfully.
pcode MyAdapter
pcode MyGUI
MyGUI.fig as it is.
Thanks you, Titus, Sean and Walter. You guys are just awesome.
Wish you nice time ahead, my problem is solved for now. i am going for beers, cheers :)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by