Filter löschen
Filter löschen

Use a double as an index for another double works once and that gives indexing error.

4 Ansichten (letzte 30 Tage)
Dear experts,
I'm facing a problem and I cannot really understand what's going wrong. I'll try to make it as simple as possible.
I have 2 doubles:
  • ampl = 1x1760;
  • coords = 1x635;
I just need to filter (is that the right word?) values from the ampl double using the coords double. To achieve that, I perform:
ampl_filtered = ampl(coords);
That works fine as I need.
Then I have other 2 doubles:
  • amplROI = 1x201;
  • coordsROI = 1x41;
I run a similar line of code
amplROI_filtered = amplROI(coordsROI);
but this time I get this error:
Index exceeds the number of array elements (201).
I don't understand what's wrong here since the doubles are similar.
Both coords and coordsROI store integers, while ampl and amplROI store float numbers.
Why I get this error? What am I doing wrong?
Tank you all!

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 22 Dez. 2020
Look at what the error message is saying. It has nothing to do with doubles vs floats. The problem is coordsROI contains value(s) that are greater than the indices available for amplROI (only 201 elements).
Here's a simple recreation of the error.
A = [1 2];
A(5)
Index exceeds the number of array elements (2).
Perhaps this page on Array Indexing is helpful?

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by