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

1 Ansicht (letzte 30 Tage)
Jan Hörber
Jan Hörber am 11 Jan. 2022
Beantwortet: Ninad am 28 Sep. 2023
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

Antworten (1)

Ninad
Ninad am 28 Sep. 2023
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.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by