Variable is changed but the value seems to be unused
Show older comments
% 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)
the cyclist
on 29 Mar 2018
Edited: the cyclist
on 29 Mar 2018
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
the cyclist
on 29 Mar 2018
Can you give an example of inputs y1, y2 that exhibits the behavior you are describing?
Walter Roberson
on 29 Mar 2018
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
HABmatlab
on 29 Mar 2018
Walter Roberson
on 29 Mar 2018
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
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!