- Add Components: From the "Component Library," add a UITable and a "button." The button will be used to update the UITable values. Your App Designer window will appear as shown below.
Basic Matlab App deisnger question regarding the Component Library
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
This is a very basic question but I coudln't find information regarind my inquery.
I have multiple slider switches on the app designer and each of them has label/name. What I wanted to do is to count the number of slider switches that are on the app, then create the for loop to obtain the slider's name then store them. Once it is stored then will display on the UITable.
I believe Matlab should have the ability to count them but I couldn't find a document for it.
댓글 수: 0
채택된 답변
Shivam Gothi
2024년 9월 14일
Hello @Min
I understand that you would like to create a UITable within the "App Designer" that lists the names of all the sliders used in your app. I am suggesting an approach to achieve this goal.
To illustrate this, I created a simple app using the App Designer and named it "app1." It includes three sliders named "slider_one," "slider_two," and "slider_three," as depicted in the image below.
Once you have created your app with the abve mentioned three sliders, please follow these steps to create a UITable of slider names:
2) Select the Button: Click on the button and navigate to the "Callback" section on the right side of the App Designer window.
3) Create a Callback Function: Add a "ButtonPushedFcn" and name it "button_pushed" or choose any suitable name. This will automatically direct you to the "Code View" section, where you will see a function created with the name you provided.
4) Enter the Code: Within the function body, please enter the lines of code provided below.
% Button pushed function: Button
function button_pushed(app, event)
%newDisplayData = app.UITable.DisplayData;
mc = metaclass(app)
SliderNameCellArray={};
index=1;
numel(properties(app));
for i=1:numel(properties(app))
if((mc.PropertyList(i).Validation.Class.Name)=="matlab.ui.control.Slider")
SliderNameCellArray{index} = mc.PropertyList(i).Name;
index=index+1;
end
end
app.UITable.Data=SliderNameCellArray';
app.UITable.ColumnName="total sliders"
end
To understand the logic behind the code, you may refer to the attached links.
5) Save and Run: Save your code and press the "Run" button on the toolstrip. This will open your app. Click the button within the app to update the contents of the table, as illustrated in the figure below.
6) Alternative Method: Instead of adding an extra button to update the table values, you can define a "callback" for the UITable and enter the same lines of code into the corresponding callback.
For your convenience, I have attached the above designed app with this answer for your reference.
You can also add additional columns to the "UItable", displaying the names of other "UI objects". Make appropriate changes to the code and refer to the above attached documents.
I hope this approach is helpful !
댓글 수: 2
Shivam Gothi
2024년 9월 29일
Yes, it is also possible to display the values of the slider on the UITable. I am suggesting one of the possible approach. Modify the code inside the "button_pushed" callback function as shown below:
function button_pushed(app, event)
%newDisplayData = app.UITable.DisplayData;
mc = metaclass(app);
SliderNameCellArray={};
index=1;
P=mc.PropertyList;
numel(properties(app));
for i=1:numel(properties(app))
if((mc.PropertyList(i).Validation.Class.Name)=="matlab.ui.control.Slider")
SliderNameCellArray{index,1} = mc.PropertyList(i).Name;
SliderNameCellArray{index,2} = app.(P(i).Name).Value;
index=index+1;
end
end
app.UITable.Data=SliderNameCellArray;
app.UITable.ColumnName={"total sliders","values"}
end
Here, one more column is added in the UITable to display the values corresponding to the sliders.
Now, save the code and run the MATLAB app. The "values" column in the "UITable" will show the corresponding values held by each slider. Please press "button" to update the values inside the UITable, each time the slider is changed. I have also attached the MATLAB app to demonstarte this.
You can refer to the below documentation link to get more information about "UISlider" object.
I hope this helps !
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!