Index in position 1 exceeds array bounds.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
As a task I have to implement a RANSAC algorithm. There is an array called correspondences which is 4xn, where the first 2 rows are x1 and y1 and the last two rows are x2 and y2. These are coordinates for pixels. The task here is to seperate the coordinates into their own homogenious variables. Before that one must provide some optional variables for the function. I used an Input Parser for that and it seems to work. This is what I did:
function [epsilon, p, tolerance, x1_pixel, x2_pixel] = F_ransac(correspondences, varargin)
% This function implements the RANSAC algorithm to determine
% robust corresponding image points
p1 = inputParser;
addOptional(p1, 'epsilon', 0.5, @(x)validateattributes(x, {'numeric'}, {'<',1}, {'>',0}));
addOptional(p1, 'p', 0.5, @(x)validateattributes(x, {'numeric'}, {'<',1}, {'>',0}));
addOptional(p1, 'tolerance', 0.01, @(x)validateattributes(x, {'numeric'}));
parse(p1);
epsilon = p1.Results.epsilon;
p = p1.Results.p;
tolerance = p1.Results.tolerance;
x1_pixel = ones(3,size(correspondences,2));
x1_pixel(1:2,:) = correspondences(1:2,:);
x2_pixel = ones(3,size(correspondences,2));
x2_pixel(1:2,:) = correspondences(3:4,:);
end
This is constantly giving me the error:
Index in position 1 exceeds array bounds.
Error in F_ransac (line 16)
x1_pixel(1:2,:) = correspondences(1:2,:);
Why is it giving me this error? What could I do to avoid it?
1 comentario
VBBV
el 3 de Jun. de 2022
correspondences = rand(3,5); % less than 4
F_ransac(correspondences,3)
function [epsilon, p, tolerance, x1_pixel, x2_pixel] = F_ransac(correspondences, varargin)
% This function implements the RANSAC algorithm to determine
% robust corresponding image points
p1 = inputParser;
addOptional(p1, 'epsilon', 0.5, @(x)validateattributes(x, {'numeric'}, {'<',1}, {'>',0}));
addOptional(p1, 'p', 0.5, @(x)validateattributes(x, {'numeric'}, {'<',1}, {'>',0}));
addOptional(p1, 'tolerance', 0.01, @(x)validateattributes(x, {'numeric'}));
parse(p1);
epsilon = p1.Results.epsilon;
p = p1.Results.p;
tolerance = p1.Results.tolerance;
x1_pixel = ones(3,size(correspondences,2));
x1_pixel(1:2,:) = correspondences(1:2,:);
x2_pixel = ones(3,size(correspondences,2));
x2_pixel(1:2,:) = correspondences(3:4,:);
end
May be you are calling function with input arguments of incorrect size
Respuestas (2)
Chunru
el 3 de Jun. de 2022
It seems that your code works well. Can you show how the error occurs?
x = randn(4, 5)
F_ransac(x)
function [epsilon, p, tolerance, x1_pixel, x2_pixel] = F_ransac(correspondences, varargin)
% This function implements the RANSAC algorithm to determine
% robust corresponding image points
p1 = inputParser;
addOptional(p1, 'epsilon', 0.5, @(x)validateattributes(x, {'numeric'}, {'<',1}, {'>',0}));
addOptional(p1, 'p', 0.5, @(x)validateattributes(x, {'numeric'}, {'<',1}, {'>',0}));
addOptional(p1, 'tolerance', 0.01, @(x)validateattributes(x, {'numeric'}));
parse(p1);
epsilon = p1.Results.epsilon;
p = p1.Results.p;
tolerance = p1.Results.tolerance;
x1_pixel = ones(3,size(correspondences,2));
x1_pixel(1:2,:) = correspondences(1:2,:);
x2_pixel = ones(3,size(correspondences,2));
x2_pixel(1:2,:) = correspondences(3:4,:);
end
0 comentarios
Ver también
Categorías
Más información sobre Modulation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!