Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
??? Indexing cannot yield multiple results.

Subject: ??? Indexing cannot yield multiple results.

From: Shawn Woods

Date: 25 May, 2011 07:53:02

Message: 1 of 3

I am using the min() function to find the smallest element in a vector. It was working about 1 week ago but has stopped. Several things within the main body have changed. However, the only solution that I have found was to make sure that min is not used as a variable or other function elsewhere in the code. I have not used min() as either.

min_diff1 = ones(3001,1)

% Then, I run a loop that calculates a different values for min_diff1

for z = 0:0.0001:h1,
    loop = loop + 1;

    A1 = 1;
    B1 = 2;
    C1 = 3;

    x = a2 - z;

    x = x*((x >= 0) && (x <= b2)) + b3*(x > b3);

    angle1 = (A1*x^2 + B1*x + C1)
    diff1 = abs(angle1 - angle_s*180/pi);
    min_diff1(loop,1) = diff1;

end

[m1,n1] = size(min_diff1)
[o1,p1] = min(min_diff1)


I have simplified some of the variables and equations so that it can be posted here. min_diff1 shows up as a proper [3001,1] vector. The output is m1 = 3001, n1 = 1. Then, it crashes, giving me the following error:

??? Indexing cannot yield multiple results.

Error in ==> pre_cals_d_p at 50
[o1,p1] = min(min_diff1)

Error in ==> yp at 21
        pre_cals_d_p();

Error in ==> odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to
yp0.

Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
odeArgs, odeFcn, ...

Error in ==> Ctrl_Script at 69
[t,y] = ode45(@yp,[tstart tfinal],y0,options);


All variables are properly defined, even if not shown (i.e. h1). I have been trying to figure out why this doesn't work now. It used to work before I added the events function to be able to stop the integration. Is this a possible conflict? Thank you in advance for anyone who takes the time to read this and respond.

Shawn

Subject: ??? Indexing cannot yield multiple results.

From: Jos (10584)

Date: 25 May, 2011 12:31:03

Message: 2 of 3

"Shawn Woods" wrote in message <iricgu$lpk$1@newscl01ah.mathworks.com>...

* SNIP
Then, it crashes, giving me the following error:
>
> ??? Indexing cannot yield multiple results.
>
> Error in ==> pre_cals_d_p at 50
> [o1,p1] = min(min_diff1)

My guess is that you accidently defined min as a variable before arriving at this line of code. Try to take a look using, e.g., WHO

~Jos

Subject: ??? Indexing cannot yield multiple results.

From: Shawn Woods

Date: 26 May, 2011 04:39:05

Message: 3 of 3

"Jos (10584)" wrote in message <irisq7$2g2$1@newscl01ah.mathworks.com>...
> "Shawn Woods" wrote in message <iricgu$lpk$1@newscl01ah.mathworks.com>...
>
> * SNIP
> Then, it crashes, giving me the following error:
> >
> > ??? Indexing cannot yield multiple results.
> >
> > Error in ==> pre_cals_d_p at 50
> > [o1,p1] = min(min_diff1)
>
> My guess is that you accidently defined min as a variable before arriving at this line of code. Try to take a look using, e.g., WHO
>
> ~Jos


Thanks for the help Jos. In an area, I had a minW and maxW and apparently I had accidentally removed a W somehow recently. I never knew about the who command. I was able to fin the min quickly. It was in the most unlikely and untouched area. I must have uncommented the area by accident.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us