Convert each "block of 5 bard" to a number according to the table above. Store each digit in a row vector. Use a for loop for this step.

1 view (last 30 days)
Convert each "block of 5 bard" to a number according to the table above. Store each digit in a row vector. Use a for loop for this step.
This is what I tried and I am still getting just the barcode dots back not the numbers that they equal to:
for i = 1:length(barcodes)
regexprep(barcodes{i,1}, '...::', '1');
regexprep(barcodes{i,1}, '..:.:', '2');
regexprep(barcodes{i,1}, '..::.', '3');
regexprep(barcodes{i,1}, '.:..:', '4');
regexprep(barcodes{i,1}, '.:.:.', '5');
regexprep(barcodes{i,1}, '.::..', '6');
regexprep(barcodes{i,1}, ':...:', '7');
regexprep(barcodes{i,1}, ':..:.', '8');
regexprep(barcodes{i,1}, ':.:..', '9');
regexprep(barcodes{i,1}, '::...', '0');
end

Answers (1)

Image Analyst
Image Analyst on 29 Nov 2013
Try this:
% Make look up table
barcodes = { '...::'
'..:.:'
'..::.'
'.:..:'
'.:.:.'
'.::..'
':...:'
':..:.'
':.:..'
'::...'}
% Run this same thing through the lookup table,
% converting dots to numbers.
for k = 1 : length(barcodes)
% Extract one of the bar codes.
thisBarCode = barcodes{k};
[itIsInThere, row] = ismember(thisBarCode, barcodes);
theNumber(k) = rem(row, 10);
% Print out to command window
fprintf('%s equates to %d\n', ...
thisBarCode, theNumber(k));
end
In command window:
barcodes =
'...::'
'..:.:'
'..::.'
'.:..:'
'.:.:.'
'.::..'
':...:'
':..:.'
':.:..'
'::...'
...:: equates to 1
..:.: equates to 2
..::. equates to 3
.:..: equates to 4
.:.:. equates to 5
.::.. equates to 6
:...: equates to 7
:..:. equates to 8
:.:.. equates to 9
::... equates to 0

Categories

Find more on Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!