Index in position 1 exceeds array bounds (must not exceed 1)?
28 views (last 30 days)
Show older comments
I'm trying to run this function (Y is a 3 by 4 matrix)
function Y10 = RREF1 (Y)
Y1=Y(2,:)-(Y(2,1)/Y(1,1))*Y(1,:);
Y2=Y(3,:)-(Y(3,1)/Y(1,1))*Y(1,:);
Y3=Y2-(Y2(1,2)/Y1(1,2))*Y1;
Y4=Y3/Y3(1,3);
Y5=Y2-(Y2(1,3)/Y4(1,3))*Y4;
Y6=Y5/Y5(1,2);
Y7=Y(1,:)-(Y(1,3)/Y4(1,3))*Y4;
Y8=Y7-(Y7(1,2)/Y6(1,2))*Y6;
Y9=Y8/Y8(1,1);
Y10 = [Y9;Y6;Y4];
end
but I get this error each time i run RREF1 Y:
Index in position 1 exceeds array bounds. Index must not exceed 1.
Error in RREF1 (line 2)
Y1=Y(2,:)-(Y(2,1)/Y(1,1))*Y(1,:);
I don't understand which array is it talking about? I know Y does have more than one row or column
0 Comments
Accepted Answer
Star Strider
on 19 Nov 2021
There must be something interfering with the function, since the code runs correctly here —
Y=[1 -3 5 -9; 2 -1 -3 19;3 1 4 -13]
Yout = RREF1(Y)
function Y10 = RREF1 (Y)
Y1=Y(2,:)-(Y(2,1)/Y(1,1))*Y(1,:);
Y2=Y(3,:)-(Y(3,1)/Y(1,1))*Y(1,:);
Y3=Y2-(Y2(1,2)/Y1(1,2))*Y1;
Y4=Y3/Y3(1,3);
Y5=Y2-(Y2(1,3)/Y4(1,3))*Y4;
Y6=Y5/Y5(1,2);
Y7=Y(1,:)-(Y(1,3)/Y4(1,3))*Y4;
Y8=Y7-(Y7(1,2)/Y6(1,2))*Y6;
Y9=Y8/Y8(1,1);
Y10 = [Y9;Y6;Y4];
end
See if there is another ‘RREF1’ function somewhere that could be running instead of this one.
.
0 Comments
More Answers (1)
Cris LaPierre
on 19 Nov 2021
Apparently there is only one row in Y, and your code is trying to access a second row.
Y = 1:3
% Works
Y (1,1)
% Doesn't Work
Y(2,1)
3 Comments
Cris LaPierre
on 19 Nov 2021
You may have redefined Y somewhere in your code before it gets passed into RREF1. Your function is only getting a 1xn vector for Y, and not a 3x4 matrix.
How do you call RREF1 in your code?
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!