Index in position 1 is invalid.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Good day,
I have made the following Script to sotre the coordinates of centroid of laser beam from images
directory = 'C:\Users\anask\Desktop\test\';
Coordination = zeros(7,3);
files = dir([directory '/*.jpg']);
[~,index] = sortrows({files.date}.'); files = files(index); clear index;
for x = 1: numel(files)
A= imread([directory '/' files(x).name]);
%Convert the image ino binary image
Ibw = im2bw(A);
%Fill image regions and holes
Ibw = imfill(Ibw,'holes');
Ilabel = bwlabel(Ibw);
%finding the centroid
stat = regionprops(Ibw,'Area','Centroid');
%Creating new array that have Area, X-coordinate, Y-coordinate
area = cat(1,stat.Area);
Coor = cat(1,stat.Centroid);
%Combaining the results in one Array
Array = cat(2,area,Coor);
%Adding header
%header = {'Area','x','y'};
%Array = [header; num2cell(Array)];
%Finding the maximum value
maximum = max(max(Array(:,1)));
[x,y]=find(Array==maximum);
%Apped the line of the maximum value in a new array
if ~isempty(Coordination)
Coordination(i,1:2) = Array(x,2:3);
end
clear stat
clc
end
And I am keep getting the following error
----------------------------------
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in Test (line 34)
Coordination(i,1:2) = Array(x,2:3);
------------------------------------
Can someone help me please to fix this issue, I want to store the coordinates in the coordinate array. The coordinate are derived from the row of the maximum area in 'Array' array.
Many thanks in advanced
0 comentarios
Respuesta aceptada
G A
el 9 de Jul. de 2021
i as an index is not defined in your code, Matlab considers it as 1i by default
4 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!