Changing a Drop Down component items via a string.

Hi all,
I am making a GUI for my XML files. The problem is related to a Drop Down component. As shown in the picture:
In the last column (option) and second row, a 1x6 string exist. Here is ther problem. When I manually define a 1x6 string array using the code bellow:
B = ["Red","Yellow","Blue","Green"];
I can change component's items. But, when I use the bellow opcode:
inStruct.input.group.group(1).param(2).option
An error emerges!
Anyway, my question is how it is possible to change my drop down menu items by the items included in the second row and last column?
TNX.

回答 (1 件)

T.Nikhil kumar
T.Nikhil kumar 2024 年 5 月 16 日

0 投票

Hello Hannan,
I understand that you want to change the items of a dropdown in your app with a string array present in another variable in your workspace.
I do not think there is a direct way to use a workspace variable as the dropdown items value.
I suggest you to try the following method for accessing the string array and assign the value as dropdown items.
1. Save the ‘inStruct’ variable in a ‘.mat’ file
save sampleFile inStruct
2. Now, define a startup function for the app, using the ‘StartupFcn’ callback for the app where you can load the required string array from this ‘.mat’ file and assign it to the dropdown’s items list.
fileContent = load('sampleFile.mat');
app.DropDown.Items = fileContent.inStruct.input.group.group(1).param(2).option;
You can run the app and verify if you can see the items in the dropdown. In case the string array in the ‘inStruct’ variable is changed and you want to show the new string array as the dropdown’s items, you will have to save ‘inStruct’ again in ‘sampleFile.mat’ and then run the app.
Hope this helps you proceed with your work!

3 件のコメント

S. Hannan
S. Hannan 2024 年 5 月 16 日
Thanks for your response.
Actually, I am using App Designer to build the GUI. An XML file is imported via pressing the import botton and all of the variables is assigned by the imported file and not the workspace. The worksapce in the first image is used to convey my mean. As you can see, the list box items in the secons image have been changed based on the file.
The opcode you mentioned in your response was one of the commands I have used so far (see the following picture). But it doesn't work at all!
I want to make the Drop Down items sensitive to the List Box counterparts. For example, by selecting the second item in the List Box, I want to update the Drop Down items based on the 1x6 string.
Let me know if further information is needed.
T.Nikhil kumar
T.Nikhil kumar 2024 年 5 月 16 日
Can you show the part where you're getting inStruct into your code?
S. Hannan
S. Hannan 2024 年 5 月 16 日
[infile,location] = uigetfile('*.xml');
inStruct = readstruct(infile);

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

製品

リリース

R2024a

タグ

質問済み:

2024 年 5 月 16 日

コメント済み:

2024 年 5 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by