How can i control a uicheckbox based on excel cell value Yes or No

I have an excel cell value for a parameter to be YES NO. Now i am importing this in my function and then creating folders to store the excel values After that i want to modify my checkbox by the values from excel cell

1 comentario

And which part of this process is causing you trouble? Have a read here and here. It will greatly improve your chances of getting an answer. Your current question is a description for a consultant, not a question.

Iniciar sesión para comentar.

Respuestas (1)

Cris LaPierre
Cris LaPierre el 15 de Ag. de 2023
Basically, you need to programmatically convert your yes/no to true/false, and use that to set the Value property of your checkbox.

11 comentarios

PA
PA el 15 de Ag. de 2023
Editada: PA el 15 de Ag. de 2023
i already have programitically created a ui checkbox . I want to add this as a Autocalc in a classdef properties
function createUI(app)
PIUserInputGridLayout = uigridlayout(app.coredata.User);
PIUserInputGridLayout.ColumnWidth = {275 50, '1x', 30};
PIUserInputGridLayout.RowHeight = {40,40,40,40,40,50,100,40};
PIUserInputGridLayout.Scrollable = 'on';
PI.Autocalc = uicheckbox(PIUserInputGridLayout);
PI.Autocalc .Layout.Row = 1;
PI.Autocalc .Layout.Column = [1,4];
PI.Autocalc .Text = 'Automated';
PI.Autocalc .Value = 0 ;
PI.Auto .ValueChangedFcn = (@(cbx,event) AutocalcButtonPushed(cbx));
function AutocalcButtonPushed(cbx)
if cbx.Value
PI = clsPI.PIcalcrule(app, PI);
PI.AddPIButton.Enable = 'off' ;
set(findall(PIUserInputGridLayout, 'Type' , 'uilabel' ), 'enable' , 'on' )
else
PI.AddPIButton.Enable = 'on' ;
set(findall(PIUserInputGridLayout, 'Type' , 'uilabel' ), 'enable' , 'off' )
end
end
end
Ok. None of the code you have shared reads values from an Excel sheet and uses that info the set the Value property of the check box.
Here is the excel cell .
I am calling this excel file in a different function file
data = readtable(C:\Users\rama\Documents\excel_Y_N.xlsx);
And then creating combination of the excel cell and then calling the
objDesign_k.PI.Autocalc = objDesign.PI.Autocalc;
checkboxdata = strcmp(objDesign.PI.Autocalc;,"YES")
Can you share a runnable example? Looking at code snippets out of context makes it hard to provide a meaningful solution, or understand why the answer provided already is not working.
At least part of the problem is your table format - you have mixed data types in some of your columns. Since you are not specifing import options, readtable is trying to automatically determine the data type for each column. Since your first row contains number data in columns 4-5, it treats all data in those columns as numbers. Anything that is not a number is convereted to nan, including 'yes' and 'no'.
You will need to treat those columns as text if you want to capture the text values. Just be aware that the numbers will also strings instead of doubles.
% What is currently happening
data = readtable('excel_Y_N.xlsx')
data = 5×5 table
Var1 Var2 Var3 Var4 Var5 ____ ________________ _______________ ____ ____ 1 {'distance1' } {'d1' } 5 10 2 {'distance2' } {'d2' } NaN NaN 3 {'distance3' } {'d3' } NaN NaN 4 {'distance4' } {'d4' } NaN NaN 5 {'Pi Selection'} {'Pi.Autocalc'} NaN NaN
% Specifying import options
opts = detectImportOptions("excel_Y_N.xlsx");
opts = setvartype(opts,4:5,"string");
data = readtable("excel_Y_N.xlsx",opts)
data = 5×5 table
Var1 Var2 Var3 Var4 Var5 ____ ________________ _______________ _________ _________ 1 {'distance1' } {'d1' } "5" "10" 2 {'distance2' } {'d2' } <missing> <missing> 3 {'distance3' } {'d3' } <missing> <missing> 4 {'distance4' } {'d4' } <missing> <missing> 5 {'Pi Selection'} {'Pi.Autocalc'} "Yes" "No"
PA
PA el 16 de Ag. de 2023
Editada: PA el 16 de Ag. de 2023
thanks and yeah it has mixed data type therefore i had to create the combination using nested loop comb =
8×3 cell array
{'5' } {'9'} {'Yes'}
{'10'} {'9'} {'Yes'}
{'5' } {'9'} {'No' }
{'10'} {'9'} {'No' }
{'5' } {'9'} {'No' }
{'10'} {'9'} {'No' }
{'5' } {'9'} {'Yes'}
{'10'} {'9'} {'Yes'}
then convert this output to string and double
combinationOutput =
8×3 table
d1 d3 Pi.Autocalc
__ __ ___________
5 9 "No"
5 9 "No"
5 9 "Yes"
5 9 "Yes"
10 9 "No"
10 9 "No"
10 9 "Yes"
10 9 "Yes"
The basic idea is importing the excel file creating combination storing this new combinations in a new variant and then exporting
And then creating combination of the excel cell and then calling the
objDesign_k = objDesign;
objDesign_k.PI.Autocalc = objDesign.PI.Autocalc;
checkboxdata = strcmp(objDesign.PI.Autocalc;,"YES")
I want to read this combinations values and change my interface accordingly for example in the first case 5 9 "No" then the value of d1 shall assign to 5 d3 to 9 and the checkbox need to be uncheck as it is No and vice versa if the combination has Yes in it and i have no idea how to do it. Please help me!
Cris LaPierre
Cris LaPierre el 16 de Ag. de 2023
Editada: Cris LaPierre el 16 de Ag. de 2023
Tables can contain variables (columns) with different data types. That's one of the benefits of using tables. However, all the values in a variable must be of the same data type. The example you show above would work fine, but the xlsx file you shared is arranged differently.
Thanks however I am sorry i didnt get you, Could you be more specific
The table in excel_Y_N.xlsx looks like the image I shared, not like this
i just added a new value'9' to the parameter d3. And can you tell me how can i check and uncheck the ui check box with the tableYES or NO with the code i shared here
Cris LaPierre
Cris LaPierre el 16 de Ag. de 2023
Editada: Cris LaPierre el 16 de Ag. de 2023
I'm afraid I don't know what that means. Please provide a runnable example.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

PA
el 15 de Ag. de 2023

Editada:

el 16 de Ag. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by