Using MATLAB to load the dimensions of an object selected by the user from an excel file

4 vues (au cours des 30 derniers jours)
I have an excel file with the dimensions of different cylinders. How can I use MATLAB so that the user selects a particular cylinder from a drop down list and then the dimensions of this cylinder are then loaded into matlab for further calculation?

Réponses (1)

Rahul
Rahul le 12 Fév 2025
In order to read the data from excel into matlab, consider using 'readtable' function.
Additionally, consider using 'uidropdown' function to obtain the required dropdown functionality within a 'uifigure' and integrate it with a 'ValueChangedFcn' callback.
Here is an example:
% Read the excel data
data = readtable('Book2.xlsx');
% Here I have assumed that the Excel file has columns:
% 'CylinderName', 'Diameter', 'Height' - This can be adjusted accordingly
cylinderNames = data.CylinderName;
% Create the user interface
fig = uifigure('Name', 'Select a Cylinder');
dropdown = uidropdown(fig, ...
'Items', cylinderNames, ...
'Position', [100, 150, 150, 22], ...
'ValueChangedFcn', @(dd, event) loadCylinderDimensions(dd, data));
% Callback function to load dimensions (This can be adjusted according to user requirements)
function loadCylinderDimensions(dd, data)
selectedCylinder = dd.Value;
idx = strcmp(data.CylinderName, selectedCylinder);
fprintf('Selected Cylinder: %s\n', selectedCylinder);
fprintf('Diameter: %.2f\n', data.Diameter(idx));
fprintf('Height: %.2f\n', data.Height(idx));
end
The following MATLAB Answers can also be referred:
The following MathWorks documentations can be referred to know more:
Hope this helps. Thanks.

Catégories

En savoir plus sur COM Component Integration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by