How to export from a GUI (.exe) to MATLAB workspace?

Hi, Can anyone guide me how to export a created array in a GUI(.exe) to the MATLAB '*base*' workspace? Note: by GUI(.exe), I mean I've created a GUI .exe file using '*deploytool*'. If I run my GUI .m file (or .fig file using 'guide') I can use '*assignin*' function to do this export. But the mention function does not work if I run my .exe GUI. Should I run MATLAB from .exe GUI?
Thank you so much

 採用された回答

Walter Roberson
Walter Roberson 2011 年 6 月 13 日

1 投票

The .exe has its own base workspace that you can assign in to all you like, but it will vanish as soon as the executable ends -- just like happens if you were to do something in MATLAB and then exit MATLAB.
Running MATLAB from the .exe wouldn't help much, in the sense that the .exe would not be able to make assignments in to the workspace of the live MATLAB.
The .exe could save() variables in to a .mat file, and you could load() the .mat file.

7 件のコメント

math98
math98 2011 年 6 月 13 日
Dear Walter,
Let's assume we have a MATLAB opened in Win7, and an exe GUI to work on a prepared MATLAB code!
Now, do we able to load a exe GUI array (that is in its own exe base workspace) into that opened MATLAB workspace, just commanding from the GUI, by any method you know? (without opening a new MATLAB)
Thanks
Walter Roberson
Walter Roberson 2011 年 6 月 13 日
No, that cannot be done unless the .exe has been designed to communicate with other programs (such as via UDP).
math98
math98 2011 年 6 月 14 日
Walter,
Really thanks for your comments.
Actually, I'm an elec. engr. (not a software engr.)
Sorry buddy that I've not accepted the answer yet.
But, it's really funny that such a big software (with very different functions available officially or not) does not have such a basic functionality.
Do you mean "User Datagram Protocol" by UDP?
If you're sure completely about your answer; and if it's not necessary to consult others; could you plz suggest me the simplest method you think it's practical? (e.g. is it possible to run the exe from MATLAB command?)
math98
math98 2011 年 6 月 14 日
Excuse me, another Q:
Haven't you seen a possible function in the file exchange section, or another person that has had the same problem?
tnx
Gerd
Gerd 2011 年 6 月 14 日
Hi math98,
I cannot think about any software which is able to do what you want. Walter told it correctly if you want to share data between different programs you have to save the results first(.mat) and then open the data in a different program(load *.mat). If you close your .exe your computer releases memory and the data is gone.
Why do you want to run the .exe from a matlab session. If you do have the .m code just let it run and you can assign everything on the 'base' workspace.
Gerd
math98
math98 2011 年 6 月 14 日
Thanks Gerd,
but I should make exe of my code, then share it with others.
Gerd
Gerd 2011 年 6 月 14 日
Of course you can make an .exe out of your code and share the program with other users. When all user want to share data (results, input vectors) I would use the load and save functions.
It is the same as you share and .xls ord .doc file

サインインしてコメントする。

その他の回答 (2 件)

math98
math98 2011 年 6 月 14 日

0 投票

A Mathworks staff gave an answer here, but I don't know why it disappeared. (anyway thanks) Noting his answer, about reasons of making an exe file, I should explain that I make the exe just so that the main code is not accessible. As well I want to see the result in a live MATLAB, assume for a post-processing, just clicking from that GUI. The method you suggest, I first thought about it. But it's really not interesting to do that, WHILE IT'S POSSIBLE TO LOAD THE RESULTS IN THE LIVE MATLAB AUTOMATICALLY, NOT BY AN ADDITIONAL COMMAND! (sure if it's possible!)

3 件のコメント

Walter Roberson
Walter Roberson 2011 年 6 月 14 日
pcode the code if you do not want it to be accessible.
Chirag Gupta
Chirag Gupta 2011 年 6 月 14 日
I must have deleted my previous answer by mistake. A possible solution for your unique case might be to use actxserver (actxGetRunningServer) [on windows only]. I think this might work, but I haven't really tried this.
Chirag Gupta
Chirag Gupta 2011 年 6 月 14 日
Although, I agree with Walter that pcode is correct/better solution

サインインしてコメントする。

math98
math98 2011 年 6 月 14 日

0 投票

OK, I'm satisfied you software engineers cannot suggest me a better method.. :(
but pcoding is not my choice. I must still consult. Do you offer your softwares along with all the codes and installation contents separately?? I want an single exe file!!
Thanks for the comments

4 件のコメント

Chirag Gupta
Chirag Gupta 2011 年 6 月 14 日
May be I am not clearly understanding your use case. Let me clarify:
[You want to create an EXE to protect your code, but run the EXE on machines that already have MATLAB installed. When you are running the EXE, you want to see the results in the running MATLAB (live).]
There are a couple things regarding this:
a) EXEs from MATLAB compiler are typically used to run on platforms that do not have MATLAB installed.
b) Essentially, you want to be able to have the one EXE communicate with MATLAB (somewhat like software in the loop). There is no automatic way for that. You have to provide a channel (code it up) to communicate between the two. One option is UDP, another might be through COM (actxserver).
c) Regarding software distribution, there are numerous ways to offer it. The most important aspect is how is it meant to be used. If this is intended to be used in MATLAB, then pcode (IMHO) is the way to go. You can still zip all the files in one zip (or self extracting exe), script it so that it will automatically install it on the MATLAB path and offer a single gateway function to use it in MATLAB.
Walter Roberson
Walter Roberson 2011 年 6 月 14 日
Create one large file out of all of your .m files, and pcode that combined .m file.
To deal with your GUIDE .fig file, go back in to GUIDE and open the .fig file, and use the GUIDE menu to "export" the .fig file as a .m file. The result will be source code that creates the figure without needing the .fig file.
math98
math98 2011 年 6 月 14 日
I was gradually satisfied :)
Chirag,
a) why you advertise MATLAB? maybe someone wants to make an exe file out of his/her codes, just because it's the conventional way of software distribution. (let's assume I've prepared a software!)
b) I'm really scared with even these methods names!! in this case, I must employ a soft engineer! I'm just a student.
c) I was thinking about zipping the files. (.m and .fig)
but could you please tell me how to create a self extracting exe file and script it? what means scripting it so that to install in the MATLAB path? from where should I know the MATLAB path on another machine?
Walter,
I knew the point you mentioned. But, so that you seem to be a professional in MATLAB, like Chirag, why there is no inverse option to have all the codes in a single fig file?
I mean instead of exporting the fig file to a .m file, we could have a fig file without any attached .m file. I think it has a better view. (at least MATLAB editor is not opened.)
Anyway, I should remind that exporting my fig file, a .mat file is also created that GUIDE warns it must be beside the .m file while running!
Thanks guys for the time you spent
Walter Roberson
Walter Roberson 2011 年 6 月 14 日
MATLAB has communications channels available, but you have put on tight enough restrictions as to how you want them to work that it is not possible to access the channels in your design. Communication has to be specifically enabled in almost all software systems. For that to happen, *some* code has to run in the context of the program that starts up the second program. The setup might only take a couple of statements, but you have put on restrictions that do not allow _any_ execution in the starting program: you insist on a single executable that runs in a different context.
I have not looked at the details of how .fig files are implemented. I have some ideas as to why a stand-alone .fig would likely not work, but I would have to test those ideas.
Note: Chirag works for Mathworks, but I am an experienced software developer who uses MATLAB as a customer; I have never had access to the internal design of MATLAB and I have never had access to Mathworks policy or planning.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by