How can i control a uicheckbox based on excel cell value Yes or No
Mostrar comentarios más antiguos
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
Respuestas (1)
Cris LaPierre
el 15 de Ag. de 2023
0 votos
See this example: https://www.mathworks.com/help/matlab/ref/uicheckbox.html#buios0i-9
as well as this page: https://www.mathworks.com/help/matlab/ref/matlab.ui.control.checkbox-properties.html#responsive_offcanvas
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
Cris LaPierre
el 15 de Ag. de 2023
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.
PA
el 15 de Ag. de 2023
Cris LaPierre
el 15 de Ag. de 2023
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.
Cris LaPierre
el 15 de Ag. de 2023
Editada: Cris LaPierre
el 16 de Ag. de 2023
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')
% Specifying import options
opts = detectImportOptions("excel_Y_N.xlsx");
opts = setvartype(opts,4:5,"string");
data = readtable("excel_Y_N.xlsx",opts)
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.

PA
el 16 de Ag. de 2023
Cris LaPierre
el 16 de Ag. de 2023
The table in excel_Y_N.xlsx looks like the image I shared, not like this

PA
el 16 de Ag. de 2023
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.
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!