How can I iteract a RGB Vector between a script and a GUI

2 次查看(过去 30 天)
Hello,
I tried to exchange a RGB Color information between a Variable from a Script into a Matlab GUI. I used to try it withe the getappdata function but it didn't worked.
The The RGB Color information gets sorted out to a text string (green, blue, red) and then should be transfert to a GUI to change a lamp into the transfered color. How does ist work?
Thanks in advance

回答(1 个)

Ninad
Ninad 2023-9-28
Hi Jan,
You can use the setappdata” and “getappdata” functions to exchange color information between a MATLAB script and the application.
I have made a dummy application using two files, "script.m" and "gui.m":
  1. The "script.m" file stores the RGB colour information in three different variables named "blueColor",greenColor”, and “redColor”. The “setappdata” function is used in this script to store the data in the User Interface.
  2. The "gui.m" file is used to create the user interface with three buttons named “Blue”, “Green”, and “Red. Every button will trigger a different callback function when pressed. Within the callback function, the “getappdata” function is used to retrieve the variable values that were passed from the "script.m" file. Then, the color of the application is changed using the “set” function.
This is what the User Interface will look like:
I have attached the scripts with this answer. Run the scripts in the following order
  • script.m
  • gui.m
You may refer the following documentations to understand the usage of these functions in detail:
Thanks,
Ninad.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by