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

1 次查看(过去 30 天)
Garabani
Garabani2021-11-11
评论: Stephen ,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 个评论

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by