A variable index must be a real positive integer Issue in app designer
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Tamim Hussain
el 12 de Oct. de 2018
Comentada: Kevin Chng
el 15 de Oct. de 2018
Hi,
I have created a callback on the Control Total button (please see image) to sum of the field of my table based on the drop down value. It successfully sums the field for numeric data, however when I run the application and want to sum company code, which is the first item in my drop down, it gives me the following error; A variable index must be a real positive integer.
I am able to sum company code if I change the drop down first and go back to it, but cannot sum the field without having to change the drop down value, otherwise the error shows.
Any way I can fix this?
10 comentarios
Guillaume
el 15 de Oct. de 2018
"app.FieldsDropDown.Value will not return you the number of position of your selection"
Indeed, it returns the content of the dropdown. That's not particularly a problem, as long as whatever that content is either a strictly positive integer less than or equal to the number of variables in the table or that it is a char array/string that is a valid variable name of the table.
That is for the line
total = sum(app.UITable.Data.(app.ddValue));
to work, the following values are ok:
app.ddValue = 1;
app.ddValue = width(app.UITable.Data);
app.ddValue = 'somevalidvariablename';
but not:
app.ddValue = []; %throws: A variable index must be a real positive integer
app.ddValue = -1; %throws: A variable index must be a real
app.ddValue = 1.5; %throws: A variable index must be a real
app.ddValue = width(app.UITable.Data) + 1; %throws: Variable index exceeds table dimensions
app.ddValue = 'invalid var name'; %throws: unrecognized variable name 'invalid var name'
Kevin Chng
el 15 de Oct. de 2018
app.ddValue = []; %throws: A variable index must be a real positive integer
app.ddValue = -1; %throws: A variable index must be a real
app.ddValue = 1.5; %throws: A variable index must be a real
app.ddValue = width(app.UITable.Data) + 1; %throws: Variable index exceeds table dimensions
app.ddValue = 'invalid var name'; %throws: unrecognized variable name 'invalid var name'
Great to see this to explain why a variable index must be a real positive integer. +1
Respuesta aceptada
Guillaume
el 12 de Oct. de 2018
Could it be that the fields drop down values are empty before the data is imported?
dbstop if error
before running your code. Run your code and when it breaks into the debugger because of the error, check the value of app.ddvalue.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!