why in this function they use empty square brackets?
조회 수: 8 (최근 30일)
이전 댓글 표시
and how exactly this is solving the determinant, I don't completley understand what they did here/
sorry if it's a dumb question I'm new to coding and to matlab.
function det = myDet(A)
if isscalar(A)
det = A;
return
end
det = 0;
top_row = A(1,:);
A(1,:) = [];
for i = 1:size(A,2) % number of columns
A_i = A;
A_i(:,i) = [];
det = det+(-1)^(i+1)*top_row(i)*myDet(A_i);
end
end
댓글 수: 0
채택된 답변
John D'Errico
2021년 11월 13일
편집: John D'Errico
2021년 11월 13일
It is not a dumb question at all, because the syntax used by MATLAB to delete a row or column of an array may not be obvious. But the best way, as others have said, is to try it out. See what happens to the array when you do that. Getting your hands dirty is the best way to learn.
A = magic(3)
% first, I'll delete the second row of A
A(2,:) = []
% Next, delete the third column of that matrix.
A(:,3) = []
추가 답변 (2개)
Cris LaPierre
2021년 11월 13일
In this context, it appears to be deleting elements from A.
Try it out in MATLAB to see what it is doing.
A = rand(3)
A(1,:)=[]
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!