# Matlab Assignment Has More Non-Singleton Rhs Dimensions Than Non-Singleton Subscripts

I am trying to Optimize these set of equations to find vector **c** with i=1,2:

Bold variables are 3D Vectors.

Known Variables: R, **o**, **u1**, **u2**, **l1**, **l2**

My code works when I use ** fsolve** but gives me an error for

*fminsearch***fun.m** :

**script.m** :

OUTPUT:

## Why is your error happening?

This is due to the fact that your statement returns an empty array. This means that your array does not have any entries that are not equal to . As you start going down into your code, will create an empty matrix as the number of elements in are 0 due to the call from earlier.

Next, when you get to this statement:

This loop does not execute as the number of elements in equals 0. When you get to this statement after:

will also give you an empty matrix. Finally, when you get to this statement:

You are trying to assign an **empty** value into a location in . Specifically, you are trying to assign one value to a location in which should be stored in , but because it's empty, this is why you are getting this error. As such, you need to double check your variable to ensure that this isn't empty before you proceed with your code.

## So where is the error happening?

I can see **why** you are getting this error, and where this is happening. If you look towards the end of your code, you have this statement:

What you are doing is you are making such that the entries are **all**. When you go back into the next iteration of your loop, the statement will return an empty array as **all** values of are equal to . Because could not find any values that are **not equal** to , returns an empty array stating that it could not find any locations in that were not equal to . This is probably not what you intended to do.

Your comment states that is being set outside of the loops before your code is executed. Though that may be the case, you are changing after the first iteration of your loops, which will inevitably give you that error you are seeing.

As such, you probably need to correct this statement - either by removing it, or modifying it so that it is the definition that you are seeking.

## Some tips for you

It really helps if you your code so that you can figure out what's going on. As such, MATLAB has some great facilities to help you debug your code so you can figure out why it isn't working. You need to set MATLAB to debug mode if you'd like to do this. If this is something you want, in your MATLAB editor, go to the line where you see the statement, and click on the horizontal dash beside the line number. You'll see a **red dot** indicating that when the function runs, the function will pause at this point.

In mode, you are able to see what the current state of execution your code is in. You can also examine what the variables look like, as well as step through line by line after this point so you can see what each line is doing. You can either type in when you're in debug mode to go to the next line, or you can do this in your MATLAB editor by clicking on the **Step** buttons. There are also different buttons you can choose from:

**Continue**- Continue running your code until you reach the next breakpoint or the function exits**Step**- Run the next line of code**Step In**- Run the next line of code. If this line is a**function**, then you will go inside the function and be able to debug the statements within there. If you just do**Step**, it runs the function, but doesn't go inside. As such, this runs the entire function before pausing at the next line.**Step Out**- If you are inside a function, doing this will run the code until the function leaves. The code will then pause right after the point where you leave the function and you continue from there.

For more information on MATLAB debugging, check out this great MathWorks link here: http://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html#brqxeeu-178

## 0 thoughts on “Matlab Assignment Has More Non-Singleton Rhs Dimensions Than Non-Singleton Subscripts”