MATLAB: Corr Function not working for Spearman
The Code
Rm = corr(timeModel, 'Type', 'Spearman');
Rm
%First row of Rm contains the correlation coefficients between the values of avgExcTime and the expected execution times for all the possible values of KEY3:0
Rc = Rm(1,2:17);
%The entry of Rc with the highest positive value corresponds to the guessed
%key (the first entry of Rc is 1 and corresponds to the autocorrelation of
%avgExcTime, therefore is discarded)
[corr,idx] = max(Rc);
guessedKeyNibble = idx-1```The error
The Code
Rm = corr(timeModel, 'Type', 'Spearman');
Rm
%First row of Rm contains the correlation coefficients between the values of avgExcTime and the expected execution times for all the possible values of KEY3:0
Rc = Rm(1,2:17);
%The entry of Rc with the highest positive value corresponds to the guessed
%key (the first entry of Rc is 1 and corresponds to the autocorrelation of
%avgExcTime, therefore is discarded)
[corr,idx] = max(Rc);
guessedKeyNibble = idx-1```The error
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in Part3 (line 60) Rm = corr(timeModel, ‘Type’, ‘Spearman’); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^```
What can fix this? The TimeModel has a size of 16 x 17 which is correct and I am really lost as to what is going wrong here?
NOTE:-
Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.
It looks like you’ve encountered a naming conflict with MATLAB’s built-in corr
function. Here's what's happening and how you can fix it:
The Issue
You likely executed a line similar to:
[corr, idx] = max(Rc);
It looks like you’ve encountered a naming conflict with MATLAB’s built-in corr
function. Here's what's happening and how you can fix it:
The Issue
You likely executed a line similar to:
[corr, idx] = max(Rc);
By assigning the output to a variable named corr
, you shadow MATLAB's built-in corr
function. As a result, any subsequent calls to corr(...)
are interpreted as attempts to index into your variable corr
rather than calling the function.
How to Fix It
- Clear the Conflicting Variable
- Remove the
corr
variable from your workspace to restore access to the built-in function:
SEE COMPLETE ANSWER CLICK THE LINK
https://www.matlabsolutions.com/resources/matlab-corr-function-not-working-for-spearman.php
https://matlabarticlesworld.blogspot.com/2024/11/matlab-corr-function-not-working-for.html