error (colon operator)
6 views (last 30 days)
Show older comments
function [ string ] = get_letters( in_letters,cellsize,
lib, lib_lut )
%GET_LETTERS Interprets input letters and converts to text
% in_letters: Input letter to convert
% lib: Library of letters to use to compare
% lib_lut: lookup table to convert
best_match = [-2 0];
maxH = size(in_letters{1},1);
string = '';
%compare input image against each library letter
for i=1:cellsize
%we have a space if number of elements is 1
if( numel(in_letters{i}) <= 2 )
%ignore non-characters
if( ~ischar(in_letters{i}) )
continue;
end
string = [string in_letters{i}];
continue;
end
img_h = size(in_letters{i},1);
lowercase = (abs(img_h - maxH) > (maxH*.2));
%resize image to match library image
img = imresize(in_letters{i}, [18 18]);
for j=1:size(lib_lut,2)
%determine the correllation coeff to choose best letter
r= abs(corr2(img,lib{j}));
if( r > best_match(1) )
best_match = [r, j];
end
end
if( lowercase == 1)
%fix lowercase letters
indx = best_match(2);
if( mod(indx,2)==1 )
best_match(2) = best_match(2) + 1;
end
%handle special 'o' case
if( indx == 62 )
best_match(2) = 30;
end
end
if(best_match(2)>0)
newchar = lib_lut(best_match(2));
else
newchar = 'l';
best_match(1) = 1;
end
if( best_match(1) > 0 )
%append best letter to string.
string = [string newchar];
maxH = max(img_h, maxH);
end
best_match = [-2 0];
end
cellsize is 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
*in_letter is Columns 1 through 3
[21x19 logical] [16x14 logical] [21x17 logical]
Columns 4 through 6
[21x15 logical] [21x18 logical] [16x14 logical]
Columns 7 through 9
[21x18 logical] [21x15 logical] [21x16 logical]
Columns 10 through 12
[16x14 logical] [21x15 logical] [21x10 logical]
Columns 13 through 15
[21x20 logical] [22x15 logical] [21x17 logical]
Columns 16 through 18
[21x14 logical] [21x4 logical] [21x4 logical]
Columns 19 through 21
[21x13 logical] [27x7 logical] [21x18 logical]
Columns 22 through 24
[21x13 logical] [21x15 logical] [21x4 logical]
Columns 25 through 27
[21x21 logical] [16x22 logical] [21x17 logical]
Columns 28 through 30
[16x14 logical] [21x20 logical] [16x16 logical]
Columns 31 through 33
[21x16 logical] [22x15 logical] [23x20 logical]
Columns 34 through 36
[22x15 logical] [21x18 logical] [16x9 logical]
Columns 37 through 39
[21x17 logical] [16x13 logical] [21x16 logical]
Columns 40 through 42
[21x9 logical] [21x17 logical] [16x14 logical]
Columns 43 through 45
[21x19 logical] [16x16 logical] [21x27 logical]
Columns 46 through 48
[16x23 logical] [21x19 logical] [16x14 logical]
Columns 49 through 51
[21x19 logical] [22x15 logical] [21x17 logical]
Columns 52 through 54
[16x13 logical] [21x14 logical] [21x9 logical]
Columns 55 through 57
[21x14 logical] [21x14 logical] [21x14 logical]
Columns 58 through 60
[21x14 logical] [21x14 logical] [21x14 logical]
Columns 61 through 62
[21x14 logical] [21x14 logical]*
MY QUESTION IS AN ERROR
??? For colon operator with char operands, first and last operands must be char. for i=1:cellsize...................? plz tell me how i solve this problem ...........? i already test for i=char(1):cellsize but an another error come colon operands must be real scalars. plz tell how i solve this problem
1 Comment
Jan
on 21 Aug 2011
Please format the code correctly. See: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
And please ask a question. Currently we know, that you have found two errors. This is fine. But you neither post the complete messages, nor do explain, if you are able to solve the errors by your own, or what you have tried already to fix them.
Answers (1)
Jan
on 21 Aug 2011
Please read and post the error messages completely and carefully. The message does not appear in the line "for i=1:cellsize", but in "for i='1':cellsize". These quotes makes a difference. As long as you do not post the actual error message, it is up to you to find the problem.
I'm surprised, that you get a 2nd error - actually a program stops at the 1st one... However, the message is very clear: "lib and img must be same size" means, that they must be the same size, but they aren't. To fix this, modify the program such, that both variables have the same size. Sorry for this trivial answer - if you ask a question, an answer will be more precise.
[EDITED] "cellsize" is a char array. Then try this:
for cellCounter = 1:length(cellsize)
i = cellsize(cellCounter);
But then the term "in_letters{i}" will most likely fail. I have the impression, that you completely confused the indices and the contents of the arrays "in_letters" and "cellsize". Even the name "cellsize" sounds, like the variable contains the size of a cell.
Perhaps you want this:
for i = cellsize
I suggest:
- Use the debugger: Set a break point in the first line and step through the program line by line.
- If this does not help to locate the problem, clean up the posted code: It is very hard to read due to the confusing indentations and formats.
1 Comment
Walter Roberson
on 21 Aug 2011
The '1':cellsize is the user's attempt to correct the problem they mentioned in http://www.mathworks.com/matlabcentral/answers/14093-error
See Also
Categories
Find more on Data Type Identification in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!