Index exceeds array bounds. MATLAB - matlab

I'm trying to apply Jacobi method under MATLAB and write the code normally but keep getting the same error "Index exceeds array bounds." even I don't see clearly that there is an error in my code hope you really help me to recognize the problem
here's my code ,the error is at the highlighted line in the image
enter image description here

Run "dbstop if all error" and then run your code again. The debugger will stop when it hits the error, and you'll probably be able to spot that one of you array indices is out of bounds.

Related

Why openmodelica give me this array dimension error?

I'm developing a system in modelica and i have a big problem.
When i run the simulation in terminal, it display this error:
"Dimension 2 has bounds 1...3, got array subscript 0".
I suppose that an array declaration have an index out of bound, but no one of them have it. I don't know what to do. I'll leave the code here, i hope someone can help me
https://github.com/BigMautone/Drones.git
probably, the error is located in psoControllor.mo or drone.mo or collisionAvoidance.mo or System.mo

Error Numeric or logical matrix required for image CData

While reading a normal image file it is showing this error.
I can use the imread command in command window directly but not in the M-file.
I had used the imread function like this:
BW=imread('C:\Users\parikh5555\Desktop\books\matlab image\1.jpg')
The error I'm getting is:
??? Error using ==> image
Error using ==> image
Numeric or logical matrix required for image CData
That error is most likely due to the fact that you are trying to use image as a variable when it is an actual function: http://www.mathworks.com/help/matlab/ref/image.html.
Specifically, you probably ran some code that used image as a variable, that variable is now cleared from the MATLAB workspace, and when you are trying to reuse that same M-file script after, it thus spits out that error because image is no longer being shadowed as a variable and now it is actually calling the function.
That error has nothing to do with imread. As such, you should go through your M file and make sure you have no variables called image and rename them to something else to prevent shadowing over the function unintentionally.
BTW, I'm going to close your question as it's due to a simple typographical error. Please take no offence.

Grouping variable must be a vector or a character array

I have done the following:
I=imread('image.png');
I2=im2double(I);
cidx = fcm(I2,5);
When I tried running the following command:
silhouette(I2,cidx)
I got the following error:
Error using grp2idx (line 39)
Grouping variable must be a vector or a character array.
Error in silhouette (line 79)
[idx,cnames] = grp2idx(clust);
How can I solve this issue?
Thanks.
With problems like this, you want to work backwards through the errors. It states
Grouping variable must be a vector or a character array.
and obviously it is the variable clust that it is complaining about. So look at the file silhouette, and figure out what the variable clust is set to. I am imagining it is not a vector…
When you turn on the debugger to stop on error, you will be "in the function" where the error occurs and then you can examine the variables, move up and down the stack, and figure out exactly what went wrong.
If you still need more help, let us know what you got when you typed
whos clust
in the context of silhouette.

matlab convhulln issue

Using matlab's "convhulln" (3D), my code sometimes crashes complaining of "initial facet 1 coplanar with the interior". This is correct when I inspect the shape of the object visually. But could I somehow check for this before using convhulln on the object, so I could avoid crash ? And find out which direction co-planarity lies in, so I could then use convhulln in a correct way ?
If your only concern is not crashing the code, you can use the following structure:
try
% Do your calculations
catch
%This is evaluated if something went wrong
end

How to make Matlab include all the dimensions of the expression when error is thrown because dimensions not agree?

So I am debugging some Matlab code and I get the dimension-doesn't-agree-error for some expressions. It's all nice that Matlab points to the correct line etc. However it would be nice if Matlab would output the dimensions of the variables involved in the error text so I don't have to deal with sizing them up myself. Sometimes for a long expression deep in a for loop it's a real hassle to figure out what exactly all dimensions are.
So is there a setting or hack for this?
The easiest way to deal with this issue is to type dbstop if error in the command window, and then to run the code. MATLAB will then stop execution right before it would throw the error, and it will open the editor on the line where the error would be thrown. Then you can inspect the array sizes at your leisure, and you can even, in the command window, try out possible fixes, because you will have access to all the variables currently active in the code.
You can try the try-catch-end block.
E.g.
try
%# Some error prone code
a = getA(b);
catch err_msg
%# Display any information you want
disp(size(b));
%# Display the error message
disp(err_msg.identifier);
disp(err_msg.message);
end
You can also throw in a breakpoint in the catch block if you want to evaluate things yourself.