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 !
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!