Saturday, April 18, 2020

MATLAB Code Errors Debugging

1.Error in below code "Array indices must be positive integers or logical values" ?



deposits = [1000,1200,900,1000,500,800];
rates = [0.08,0.02,0.09,-0.01,0.04,0.05];
balance = deposits(1);
intrest = 0;
for i=i:7 – Error ,It should be I = 1:7
intrest = balance * rates;
balance = balance  + deposits(i) + intrest;
end




2.Incorrect dimensions for matrix multiplication. Check that the number of columns
in the first matrix matches the number of rows in the second matrix.
To perform element wise multiplication, use '.*' ?



deposits = [1000,1200,900,1000,500,800];
rates = [0.08,0.02,0.09,-0.01,0.04,0.05];
balance = deposits(1);
interest = 0;
for i=1:7
interest = balance * rates; – Error, It should be “.*” instead of “*”
balance = balance  + deposits(i) + interest;
end



3.Index exceeds the number of array elements (6).?



deposits = [1000,1200,900,1000,500,800];
rates = [0.08,0.02,0.09,-0.01,0.04,0.05];
balance = deposits(1);
interest = 0;
for i=1:7Error, It should be “1:6” instead of “1:7” bec index of vector is “1*6”
interest = balance * rates;
balance = balance  + deposits(i) + interest;
end



4.Open code files and create breakpoint to debug more on the specific line ?
Open the code file in the editor and provide the breakpoint to debug more

                                               

No comments:

Post a Comment