Index in position 1 exceeds array bounds (must not exceed 61)

조회 수: 1 (최근 30일)
Willard Zvarevashe
Willard Zvarevashe 2021년 12월 7일
답변: KSSV 2021년 12월 7일
When I run my code I get the error Index in position 1 exceeds array bounds (must not exceed 61)
Error in neph_calibration_correction (line 9)
p=polyfit([nephzero(i,2) nephspan(i,2)],[0 11.15],1); %
What am I getting wrong here? I have gone through previous solutions but seems not working.
%% calculate neph slopes
load('neph_zero_span.mat');% nephzero nephspan
nephspan=nephspan([2:4 6:end],:);
spancoefs=zeros(length(nephspan),4).*nan;
for i=1:length(nephspan)
spancoefs(i,1)=nephspan(i,1);
p=polyfit([nephzero(i,2) nephspan(i,2)],[0 11.15],1); % red
spancoefs(i,2)=p(1);
p=polyfit([nephzero(i,3) nephspan(i,3)],[0 23.86],1); % green
spancoefs(i,3)=p(1);
p=polyfit([nephzero(i,4) nephspan(i,4)],[0 44.21],1); % blue
spancoefs(i,4)=p(1);
end

채택된 답변

KSSV
KSSV 2021년 12월 7일
This error occurs, when you try to extract more number of elements then present in the array.
A = rand(10,1) ;
A(1) % no error
ans = 0.4508
A(7) % no error
ans = 0.7545
A(11) % error as there is no 11th element
Index exceeds the number of array elements. Index must not exceed 10.
Check the dimensions of your variables.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by