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

1 次查看(过去 30 天)
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