MATLAB Answers

App Designer: The Value Assigned Might Not be Used

7 views (last 30 days)
William Pang
William Pang on 29 May 2020
Commented: William Pang on 29 May 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

  0 Comments

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 29 May 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 Comments

William Pang
William Pang on 29 May 2020
Thanks Geoff for your answer. I've made the adjustments as you suggested, but I'm getting this error message:
At least I know that the 2D matrix is passing through my function which sums up the matrix and returning a value, i.e. 6.678919 e+06, but it can't display in the "Value" box.
I also tried adjusting the code with:
Output = trialfunction(app.I_M,filter_size)
app.ValueEditField.Value = Output;
and got this error message:
Any additional help will be much appreciated!!
Geoff Hayes
Geoff Hayes on 29 May 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 on 29 May 2020
Thanks Geoff! I figured that was the problem too. You've been very helpful!

Sign in to comment.

More Answers (0)