Variable is changed but the value seems to be unused

% code
function output = crosscorr1(y1,y2)
xcf = crosscorr(y1, y2);
[xcf,lags,bounds] = crosscorr(y1,y2);
if xcf(:,:) >= bounds(1,1)
xcf(:,:) <= bounds(1,2)
Significance(1).Sig = 'yes'
else
Significance(1).Sig = 'no'
end
end
I want to state in the Significance array, row 1, column Sig 'yes' or 'no' depending on the if/else statement. I keep receiving a message that the variable (Significance) is not used. When I check this variable, it is indeed not used even though the if/else statement appears to be working. How can I get this to work? Thank you for your help in advance.

Answers (2)

I assume that xcf is not a scalar. If that is the case, then in the statement
if xcf(:,:) >= bounds(1,1)
all of the elements of xcf have to satisfy the condition, to enter into that control structure. In other words, the if is not parallelized.

2 Comments

Hi, Thank you for your response.
Xcf is not scalar (it is a 41 X 1 double), it refers to table with one column of numbers. The if statement works if I replace:
% code
Significance(1).Sig = 'yes'
else
Significance(1).Sig = 'no'
with
% code
Disp('yes')
else
Disp('no')
The if/else statement also works when I put it in a script, it just does not work when it is in a function file. Do you think it may have something to do with the function file? Or do I need to make xcf scalar somehow to do this?
Can you give an example of inputs y1, y2 that exhibits the behavior you are describing?

Sign in to comment.

Note that your code
if xcf(:,:) >= bounds(1,1)
xcf(:,:) <= bounds(1,2)
is equivalent to
if all(xcf >= bounds(1,1))
disp( reshape(xcf <= bounds(1,2), size(xcf, 1), []) )
Is that what you want? Or do you want something like
if all( xcf(:) >= bounds(1,1) & xcf(:) <= bounds(1,2) )

2 Comments

Hi Walter, thank you for your response.
I actually want if ANY value in xcf is larger than bounds(1,1) or smaller than bounds (1,2) for a "yes" to be put into array Significance(1).Sig. I was able to get the following code to work:
%
if any(xcf >= bounds(1,1));
any(xcf <= bounds(1,2));
disp('yes')
else
disp('no')
end
So I can display a "yes" or "no" but I can't get it to go into the array.
if any( xcf(:) >= bounds(1,1) ) || any(xcf(:) <= bounds(1,2))
Significance(1).Sig = 'yes';
else
Significance(1).Sig = 'no';
end
... But your function returns output which you never assign a value to, and does not return Significance

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 29 Mar 2018

Commented:

on 29 Mar 2018

Community Treasure Hunt

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

Start Hunting!