Error using + Matrix dimensions must agree.

1 vue (au cours des 30 derniers jours)
Vignesh
Vignesh le 24 Avr 2014
Commenté : the cyclist le 25 Avr 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 commentaires
dpb
dpb le 25 Avr 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 le 25 Avr 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by