Storing UI component names in a property

2 views (last 30 days)
Hi! I am developing an app, and I've run into a problem. My app requires changing image sources for multiple different images, and so I decided to create a function that does that. I want to store the path to image sources in a property, as this would greatly reduce the complexity of the rest of the code, and so I tried to create a property imagenum like this:
properties (Access = private)
imagenum = [app.IM1.ImageSource app.IM2.ImageSource app.IM3.ImageSource app.IM4.ImageSource app.IM5.ImageSource app.IM6.ImageSource app.IM7.ImageSource app.IM8.ImageSource app.IM9.ImageSource app.IM10.ImageSource app.IM11.ImageSource app.IM12.ImageSource app.IM13.ImageSource app.IM14.ImageSource]
images = ['1.png', '2.png', '3.png', '4.png', '5.png', '6.png']
lettnum
corg
end
The corg, images and lettnum properties are there for the function, no problems with these.
And the function would look like:
function imageset(app,imnum)
if app.corg(imnum) == 1
app.imagenum(imnum) = app.images(app.wlettnum(imnum));
end
The error I get is
Error using Mainapp/GoPressed (line 60)
Invalid default value for property 'imagenum' in class 'PlayApp':
Unable to resolve the name app.IM1.ImageSource.
And so, I want to ask if there's any way to save a UI component property i.e. app.IM1.ImageSource in an app's property so it can be accessed by a function? I've tried multiple ways(saving the name as char type, string type, including .ImageSource in the function and in property), but none of these seem to be working, unless I'm missing something.

Answers (1)

Wiktor Galecki
Wiktor Galecki on 6 Apr 2022
While I didn't solve the storing in a property problem, I managed to go around it by replacing the use of property storing UI names with the following:
app.("IM"+imnum).ImageSource
And so, no further help is needed!

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!