Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

??? Index exceeds matrix dimensions.

1 Ansicht (letzte 30 Tage)
Captain Singh
Captain Singh am 29 Jan. 2014
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hello everyone, I have given here my matlab program: ______________________________________________________________________________________________
function [ha hb] = func_get_h2(Elxoctet, Vlxoctet, q, rho)
abs_El0octet = abs(Elxoctet(2:end)); diff_E0 = abs(abs_El0octet - q);
% add +1 to compensate for the fact that we remove index 1 from Elxoctet diff_E0 = logical(diff_E0); index_E0 = find(diff_E0 == min(diff_E0)) + 1;
err_E0 = abs_El0octet(index_E0-1) - q; diff_E = abs_El0octet(index_E0) - q;
if (diff_E < 0) index2_E0 = index_E0 - 1; else index2_E0 = index_E0 + 1; end
if( (err_E0 > 0.0001) && (index_E0 < 2) ) h = zeros(length(rho),1); ha = zeros(length(rho),1); hb = zeros(length(rho),1); else ha = Vlxoctet(:,index_E0); hb = Vlxoctet(:,index2_E0); end
% if(err_E0 < 0.0001) % ha = Vlxoctet(:,index_E0); % hb = Vlxoctet(:,index2_E0); % else % ha = zeros(length(rho),1); % hb = zeros(length(rho),1); % end end _______________________________________________________________________________________________ when I executed the file, I got the error: ------------------------------------------------------------------------------------------------ ??? Index exceeds matrix dimensions.
Error in ==> func_get_h2 at 12 diff_E = abs_El0octet(index_E0) - q; ------------------------------------------------------------------------------------------------- Please help me to solve this problem and try to find out the possible error source. Thanks a lot to giving me your precious time. Thank you all of you.

Antworten (1)

Mischa Kim
Mischa Kim am 29 Jan. 2014
Captain, it's hard to say based on the code you provide. In the command line
diff_E = abs_El0octet(index_E0) - q;
you are trying to access an element of array abs_El0octet that does not exist. E.g., this is like trying to access the 10th element of a vector that has only a total of 9 elements.
  1 Kommentar
Mischa Kim
Mischa Kim am 29 Jan. 2014
Just a thought. If the last element of diff_EO is the smallest one
index_E0 = find(diff_E0 == min(diff_E0)) + 1;
then index_E0 is greater (by one) than the number of elements in the vector(s). And that will cause the program to crash when trying to access that (n+1)st element.

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by