# Why am I getting Subscript indices must either be real positive integers or logicals?

1 visualizzazione (ultimi 30 giorni)
Neo il 14 Lug 2015
Commentato: Neo il 14 Lug 2015
Here is the part of my code giving me problems:
channelToCorrelate = A; %A is where the modes are in real space
correlationOutput = normxcorr2(mode(:,:A), Image(:,:, channelToCorrelate));
subplot(2, 2, 3);
imshow(correlationOutput, []);
axis on;
it brings this
Subscript indices must either be real positive integers or logicals.
Error in crosscorrelationcode (line 26)
correlationOutput = normxcorr2(mode(:,:,1), Image(:,:, channelToCorrelate));
A is a matrix of numbers including complex numbers. I thought that was the problem so i tried to use
correlationOutput = logical (correlationOuput)
and
correlationOutput = round(correlationOuput)
I got the same error both times so I then used
channelToCorrelate = logical(A)
but that didn't work because A has comle values and round just brought the same error. What am missing?
##### 2 CommentiMostra NessunoNascondi Nessuno
Geoff Hayes il 14 Lug 2015
Neo - what can you tell us about channelToCorrelate and image? The error is telling you that there is a problem at line 26, so why not put a breakpoint there and re-run the code. When you get to that breakpoint you will be able to step through the code and examine the variables that are being manipulated.
Neo il 14 Lug 2015
channelToCorrelate is the matrix where a smaller image is in the actual image and image is the image itself. Would my breakpoint be dbstopline26? Thank you for your suggestions

Accedi per commentare.

### Risposta accettata

Brendan Hamm il 14 Lug 2015
I can see a few error in the line:
correlationOutput = normxcorr2(mode(:,:A), Image(:,:, channelToCorrelate))
1. The syntax does not make sense, is there supposed to be another comma?
mode(:,:A)
mode(:,:,A)
but you mention that A has imaginary values so you cannot use it to index.
2. If channelToCorrelate is the same as A then you cannot use this to index into Image.
What is it you are attempting to do with this indexing?
##### 7 CommentiMostra 5 commenti meno recentiNascondi 5 commenti meno recenti
Brendan Hamm il 14 Lug 2015
That would likely help. But it would also be useful to understand how its location in "real space" relates to the indices in the variable Image.
Neo il 14 Lug 2015
Hold on let me try to put it in better terms.

Accedi per commentare.

### Categorie

Scopri di più su Image Arithmetic in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by