Question

I have a column of numbers, and I want to find those that are greater than 10 and then record their indices. I can do that for a single index with:

[y, I] = A(A>10)

where y stores the values, I stores the index, and A is the matrix name.

but MATLAB won't let me do it for more than one index. When I tried, it gave me the error:

"Indexing cannot yield multiple results. "

Any help would be greatly appreciated because I am very new to MATLAB and haven't figured out all the tricks yet.

Était-ce utile?

La solution

You are asking matlab to return multiple results, while A(A>10) would return only a column matrix. This would be one right way to do it:

I = A > 10;
y = A(I);

Or if you want them in a single line, you can do this:

[y, I] = deal(A(A>10), A>10);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top