squeeze function returning "NaN"

Hello everyone,
I'm trying to run a correlation between a 8, 8, 33 matrix (FC_mat) and a 33, 1 matrix, therefore, I'm trying to use the 'squeeze' function on the 8, 8, 33 matrix:
for regNum1=1:8;
for regNum2=1:8;
input1=FC_mat(regNum1,regNum2,:);
FC_mat_squeeze=squeeze(input1);
end
end
"FC_mat_squeeze=squeeze(input1);" is returning a 33, 1 matrix of all "NaN". There are NaN values along the diagonal of the "FC_mat" matrix.
I appreciate any insight any of y'all might have on getting the squeeze function to ignore the NaN's in the input.
Thanks!

답변 (1개)

Paul
Paul 2022년 4월 6일

0 개 추천

squeeze() can't ignore anything. If the input to squeez() is 1 x 1 x 33 matrix of NaN, the ouptut will be 33 x 1 of NaN. What is the desired result if input1 is 1 x 1 x 33 of NaN?

댓글 수: 5

Julia Laing
Julia Laing 2022년 4월 6일
Hi Paul,
Thanks for your response. The entire input to squeeze is not NaN, instead NaN just falls along the diagonal. Here's 1 of the 33 in the input matrix:
val(:,:,1) =
Columns 1 through 7
NaN 0.0950 -0.1437 -0.2793 0.2090 0.0855 0.1387
0.0950 NaN 0.1804 -0.1684 0.0994 0.3761 0.1447
-0.1437 0.1804 NaN 0.1583 0.2734 -0.3317 0.1182
-0.2793 -0.1684 0.1583 NaN 0.0982 -0.0248 0.1099
0.2090 0.0994 0.2734 0.0982 NaN -0.0669 -0.1727
0.0855 0.3761 -0.3317 -0.0248 -0.0669 NaN 0.4872
0.1387 0.1447 0.1182 0.1099 -0.1727 0.4872 NaN
-0.2621 0.4159 0.2887 -0.1487 -0.3855 0.2945 0.2604
Column 8
-0.2621
0.4159
0.2887
-0.1487
-0.3855
0.2945
0.2604
NaN
Thank you again for your help.
Paul
Paul 2022년 4월 6일
I'm assuming that val is the same as FC_mat, and that each page of val has the same structure with NaN on the diagonal. The first time through the loops, regNum1 = regNum2 = 1, so input1 will be FC_mat(1,1,:), which will be a 1 x 1 x 33 of NaN. Is that not the case?
Julia Laing
Julia Laing 2022년 4월 6일
Your assumpation is correct. And yes, that makes sense now why I'm getting NaN. I appreciate you breaking that down. Do you have any insight into how I could write the code/loop so that my output is not all NaN's? Thank you again for your help.
The only ways that come to mind would be to replace the NaN's with actual numbers, or modify the loops so as not to process those elements, or to detect the NaN's and skip that processing, like this:
for regNum1=1:8;
for regNum2=1:8;
input1=FC_mat(regNum1,regNum2,:);
FC_mat_squeeze=squeeze(input1);
if ~any(isnan(FC_mat))
% process valid data
end
end
end
Julia Laing
Julia Laing 2022년 4월 6일
Thanks for those recommendations. Adding in the line to detect the NaN's and skip that processing is still giving me an output of all NaN's. I'll keep trying to mess with things to work around this issue.
Thanks for your help!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2022년 4월 5일

댓글:

2022년 4월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by