App Designer: The Value Assigned Might Not be Used

7 visualizaciones (últimos 30 días)
William Pang
William Pang el 29 de Mayo de 2020
Comentada: William Pang el 29 de Mayo de 2020
Hello,
So I'm trying to read an image (2D matrix) on App Designer and run it through a function to do some filtering and analysis. I see the final value that I want (I just want to sum all the values in the image matrix after applying a filter) in the command window but when I try to make it display in a box I created with AppDesigner nothing shows up. On further inspection hoering on the "output" argument of the function, I see the message "The Value assigned to the variable 'Output' might be unused.
I'm also having trouble utilizing filter_size = app.FilterSizeEditField ... when I type in a value in the box and feed it through the function it pops back saying that "size inputs must be numeric"
filter_size = app.FilterSizeEditField;
%filter_size=3;
Output = trialfunction(app.I_M,filter_size)
Output = app.ValueEditField; %Display function output in the box
Here's the code for my trialfunction:
function[S]=trialfunction(I_M,filter_size);
I_bin_regions = rangefilt(I_M,ones(filter_size,filter_size));
S=sum(I_bin_regions,'all')
end

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 29 de Mayo de 2020
William - I think that you have your assignment reversed. Instead of
Output = trialfunction(app.I_M,filter_size)
Output = app.ValueEditField; %Display function output in the box
where, in the second line, you assign the edit field to the already assigned Output, you need to assign it to the field as
Output = trialfunction(app.I_M,filter_size)
app.ValueEditField = Output;
I'm assuming that Output is the correct data type for this field. Because you are now using this variable, the warning "The Value assigned to the variable 'Output' might be unused should be eliminated.
As for the message "size inputs must be numeric", this is probably due to your edit field being a text field rather than numeric (see uieditfield for details). So either you can change this field to be numeric, or you can convert your string input to a number. See convert text to numeric values for details.
  3 comentarios
Geoff Hayes
Geoff Hayes el 29 de Mayo de 2020
Hi William - that was my mistake, you would need to do
app.ValueEditField.Value = 'some string';
So you would need to convert your number to a string with num2str as
app.ValueEditField.Value = num2str(Output);
William Pang
William Pang el 29 de Mayo de 2020
Thanks Geoff! I figured that was the problem too. You've been very helpful!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer 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!

Translated by