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

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 件のコメント

Geoff Hayes
Geoff Hayes 2015 年 7 月 14 日
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
Neo 2015 年 7 月 14 日
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

サインインしてコメントする。

 採用された回答

Brendan Hamm
Brendan Hamm 2015 年 7 月 14 日
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)
This probably should read:
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 件のコメント

Neo
Neo 2015 年 7 月 14 日
Thank you for your response.
1. What do you mean by index into an image?
2. I am trying to use the norm correlation function in Matlab to cross correlate the matrix A with an image and a segmentation of that image to see where that segmentation of the image is in the image.
Brendan Hamm
Brendan Hamm 2015 年 7 月 14 日
編集済み: Brendan Hamm 2015 年 7 月 14 日
I assume the variable Image is one which has been read into MATLAB as a variable. If so, then this is brought in as numerical values, which you are apparently trying to index into in the line:
Image(:,:, channelToCorrelate)
which says to extract from the variable Image all rows and columns of the page identified by channelToCorrelate.
If this is not what you mean, then you have to be much more explicit about what these variables in your workspace are.
Neo
Neo 2015 年 7 月 14 日
That is exactly what I mean. Why isn't it working? A itself is just a matrix, complex but still a matrix. What other info do you need to direct me?
Well if you have a 3 dimensional array (as it seems you do) the indices are all integer values. That is the first row, first column, first page of Image would be
Image(1,1,1)
Since they are all integer valued it does not make any sense to say give me every row, every column and the page equal to (3.2 - 1.2i), that is saying
Image(:,:,3.2-1.2i)
makes no sense. So what pages are you actually trying to index into? Is this where some condition is true in the matrix channelToCorrelate?
Neo
Neo 2015 年 7 月 14 日
Oh I see. But the A, by definition, is where the segmentation of the image is in real space so I'm not sure why it's not working. I think it possess some complex values though because Matlab gave me an error when I tried to use the logic function on A because I thought that was the problem initially. And yes, this is where some condition is true in the matrix A. channelToCorrelate is simply the name I gave A but is not the matrix itself if that helps at all. Do you need to see some of A's columns?
Brendan Hamm
Brendan Hamm 2015 年 7 月 14 日
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
Neo 2015 年 7 月 14 日
Hold on let me try to put it in better terms.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

Neo
2015 年 7 月 14 日

コメント済み:

Neo
2015 年 7 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by