How to produce a GUI that is almost like a mirror of another GUI.

1 回表示 (過去 30 日間)
Garabani
Garabani 2021 年 11 月 11 日
コメント済み: Stephen23 2021 年 12 月 1 日
hello everyone, as preparation for my internship, I have been practicing matlab (2019 version) and python alternating every 3 days.
During my matlab study, I choose Doctor livestreaming as a project to tackle as it was a final year assignment my seniors did, I have the following AppDesigner code which runs well after going through many materials online (audio is done through simulink).
The Properties:
classdef WEBCAM_FOR_DOCTOR < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup2 matlab.ui.container.TabGroup
Tab matlab.ui.container.Tab
Tab2 matlab.ui.container.Tab
UIAxes matlab.ui.control.UIAxes
VIDSwitch matlab.ui.control.Switch
DateTimeTextAreaLabel matlab.ui.control.Label
DateTimeTextArea matlab.ui.control.TextArea
TabGroup matlab.ui.container.TabGroup
DoctorsCommentsTextAreaLabel matlab.ui.control.Label
DoctorsCommentsTextArea matlab.ui.control.TextArea
Switch matlab.ui.control.Switch
end
properties (Access = private)
cam;
end
methods (Access = private)
function results = func(app)
end
end
methods (Access = public)
function results = func2(app)
end
end
The livestreaming: a toggle switch turns the video of UIAxis On or Off with if-statment.
% Value changed function: VIDSwitch
function VIDSwitchValueChanged(app, event)
value = app.VIDSwitch.Value;
if strcmp(value, 'On')
app.cam = webcam;
frame = snapshot(app.cam);
theSpeakerImage = image(app.UIAxes, zeros(size(frame), 'uint8'));
axis(app.UIAxes, 'image');
preview(app.cam, theSpeakerImage);
else
closePreview(app.cam);
delete(app.cam);
cla(app.UIAxes);
end
end
Comment area: using text area and storing it outside matlab.
% Value changed function: DoctorsCommentsTextArea
function DoctorsCommentsTextAreaValueChanged(app, event)
value = app.DoctorsCommentsTextArea.Value;
f=fopen('a.txt','w');
formatSpec= "%s";
for i = 1:length(value)
fprintf(f,formatSpec,value{i});
end
end
QUESTION
I am moving onto python tomorrow which is why I would like to post my question here. I have been trying to have another GUI mirror this one and tried the following methods for textbox as UIAxes would be too difficult to start with.
  1. assigin: I tried assigning the textarea into workspace using assigin(ws,var,val) but this gives error
  2. setappdata: I tried the setappdata and getappdata using global variable inside the app. I tried setting it as setappdata(APPNAME.TextArea,value ) and when that didnt work I tried with app1 and app2 as the names for the apps. I also tried setting the two apps in public property but there is still error
I went through multiwindow but have not used it for this GUI as I want 2 GUIs with none of them being dialog boxes.
I am trying to get two GUIs with one GUI being the main one and the other GUI mirroring the output of the first one.
Is there any way to do so? any help is appreciated and thank you in advance.

採用された回答

Pranjal Kaura
Pranjal Kaura 2021 年 11 月 22 日
Hey Garabani,
It's my understanding that you want to share data between 2 apps.
You can do so by calling the apps from the command window and then use app 'properties' to share data. You can refer to this link to know more about sharing data between apps using properties.
The other workaround could be to send app data to the workspace using 'assignin' functionality and then read it in the other app using the 'evalin' function. I have attached 2 app models wherein I've done the same. However, keep in mind that this method can lead to errors or wrong results , if the variables in the workspace are deleted or changed.
Hope this helps!
  3 件のコメント
Pranjal Kaura
Pranjal Kaura 2021 年 11 月 26 日
Yes, you can use 'assignin' to assign the value (i.e. frame) to a variable ('var') in the 'base' workspace, as follows
assignin('base','var',frame);
The 'assignin' approach can be used to share data between 2 apps. You can use it to reflect changes (in data/variables) made to one app, in the other app. You will still have to create 2 similar apps and then share data between them to make them work like 'mirror images'.
Garabani
Garabani 2021 年 11 月 27 日
Thank you Pranjal, I'll try this as well.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInstall Products についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by