Pack several files in one .p file
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 !
0 commentaires
Réponse acceptée
Titus Edelhofer
le 4 Jan 2012
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 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Variables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!