Index exceeds the number of array elements (10)
Show older comments
var=cell(CC.NumObjects,1)
for j=1:1:n
% clear var
var(j,1)= var(double(image(CC.PixelIdxList{1,j})))
end
%
my code is like this. CC.NumObjects=10 and for example its consists of CC.PixelIdxList{1,1} = 369x1 array. Others consist of arrays like this. "CC.Pixel dxList{1,1}" values in this are pixel indices. I'm trying to measure the variance of the values corresponding to these indices in the image matrix. but it gives this error.
6 Comments
Dyuman Joshi
on 30 Sep 2023
Edited: Dyuman Joshi
on 30 Sep 2023
The error is clear - You are trying to access an index for which data does not exist.
It's not clear what you are trying to do with this line of code.
var(j,1)= var(double(image(CC.PixelIdxList{1,j})))
You pre-allocated var as a cell array and then you are trying to use it as a variable? Makes no sense.
Without more information and the data you are working with, it is difficult to suggest how to proceed. It would be better if you could provide those and also, mention the full error you got i.e. all of the red text.
besaret koçak
on 30 Sep 2023
Dyuman Joshi
on 30 Sep 2023
Moved: Dyuman Joshi
on 30 Sep 2023
I guess you are trying to do this -
var = cell(CC.NumObjects,1);
for j = 1:n
var{j,1} = double(image(CC.PixelIdxList{1,j})));
end
besaret koçak
on 30 Sep 2023
Moved: Dyuman Joshi
on 30 Sep 2023
Dyuman Joshi
on 30 Sep 2023
Edited: Dyuman Joshi
on 30 Sep 2023
Attach the data you are working with. Use the paperclip button to do so.
Once again, why are you trying to use an empty cell array as a variable as and then over-writing it?
var{j,1} = var(double(image(CC.PixelIdxList{1,j})));
besaret koçak
on 30 Sep 2023
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!