Array indices must be positive integers or logical values.

A = [1 2 3; -4 1 2; 0 9 -8];
B = [12; 13; -1];
solution = A\B
solution = 3×1
-1.2424 2.3939 2.8182
det = det(A)
det = -198
Can anyone tell me why i keep getting error?
Array indices must be positive integers or logical values.
det = det(A)

답변 (3개)

Torsten
Torsten 2023년 5월 17일
편집: Torsten 2023년 5월 17일

0 개 추천

I don't get this error message (see above). But you should rename the result from det(A) - otherwise you have "overwritten" the built-in MATLAB function "det" with the numerical value -198.

댓글 수: 2

It used to work before but I am not sure why I keep getting this error now and I did rename it but doesn't seem to work
You will not be able to call the det function while a variable named det is in your workspace. Renaming the variable in your code will not rename the variable that was created in the workspace by a previous run of your code. Change your code, clear the variable, then run the updated code.

댓글을 달려면 로그인하십시오.

Luca Ferro
Luca Ferro 2023년 5월 17일

0 개 추천

You cannot name a variable with the same name as a built-in matlab function.
Change the line det=det(A) to something else like detA=det(A).

댓글 수: 3

I have tried that but doesn't seem to work
John D'Errico
John D'Errico 2023년 5월 17일
편집: John D'Errico 2023년 5월 17일
If you tried it, and it did not work, then you still have a variable named det in your workspace!
Just changing the line where you created det as a variable will not help, if you will then re-run this script without deleting the variable you just named det.
exactly. use this before rerunning the script.
clear det
i would not use clear all since there may be variables you want to keep in the workspace.

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2023년 5월 19일
Type
clear all;
to get rid of your "det" that you created previously, and then run your code either in a script or the command window.
clear all;
A = [1 2 3; -4 1 2; 0 9 -8];
B = [12; 13; -1];
solution = A\B
detA = det(A)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2023년 5월 17일

댓글:

2023년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by