Pack several files in one .p file

7 visualizaciones (últimos 30 días)
Sukuchha
Sukuchha el 4 de En. de 2012
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 !

Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 4 de En. de 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 comentarios
Sukuchha
Sukuchha el 4 de En. de 2012
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 el 4 de En. de 2012
No, classdef must be in separate files.

Iniciar sesión para comentar.

Más respuestas (1)

Sukuchha
Sukuchha el 4 de En. de 2012
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 :)

Categorías

Más información sobre Variables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by