Storing UI component names in a property

2 ビュー (過去 30 日間)
Wiktor Galecki
Wiktor Galecki 2022 年 4 月 6 日
回答済み: Wiktor Galecki 2022 年 4 月 6 日
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.

回答 (1 件)

Wiktor Galecki
Wiktor Galecki 2022 年 4 月 6 日
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!

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by