Error using + Matrix dimensions must agree.

1 visualización (últimos 30 días)
Vignesh
Vignesh el 24 de Abr. de 2014
Comentada: the cyclist el 25 de Abr. de 2014
This function implements Boyer moore string matching algorithm. It gives me the following error message at line 19 (start_pos = start_pos + lookup_table(last_Char));
Both start_pos and the index i am looking in lookup_table is 1 * 1 based so i dont get where matrix size mismatch? Can anyone help me with this ??
Error using +
Matrix dimensions must agree.
Error in boyer (line 19)
start_pos = start_pos +
lookup_table(last_char);
function [final_count] = boyer(haystack, needle, nlength, start_pos, end_pos )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
temp_count = 0;
final_count = 0;
offset = nlength;
lookup_table = createTable(needle, nlength);
while(start_pos <= end_pos - nlength + 1)
last_char = haystack(start_pos + nlength - 1);
if(last_char == needle(nlength) & strncmpi(haystack(1,start_pos:end_pos), needle, nlength - 1) == 1)
temp_count = temp_count + 1;
end
start_pos = start_pos + lookup_table(last_char);
end
final_count = final_count + temp_count;
end
  5 comentarios
dpb
dpb el 25 de Abr. de 2014
Need to format your code so it's legible...simplest I've found is to just type two spaces at the beginning of a line starting a new paragraph. Keep at it until it looks right in the preview window.
Probably the easiest way for you to find the problem is to use the debugger and when you reach the error point and stop look at the size() of the various terms to see who's the actual culprit. One thought I can't tell easily w/ the unformatted code and little context is is it possible lookup_table ever returns []?
the cyclist
the cyclist el 25 de Abr. de 2014
Ideally, give us the smallest possible self-contained code that we can run. This makes debugging much faster for us. It is also quite common to discover the error yourself, in the process of making that small amount of code.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by