Error using + Matrix dimensions must agree.

조회 수: 1 (최근 30일)
Vignesh
Vignesh 2014년 4월 24일
댓글: the cyclist 2014년 4월 25일
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
dpb
dpb 2014년 4월 25일
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 2014년 4월 25일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by