0

Here is my code

%This function takes an array of 128Bvalue numbers and returns the equivalent binary
%values in a string phrase

function [PhrasePattern] = GetPatternForValuesFinal(BarcodeNumberValues)
    load code128B.mat;
    Pattern = {};
    %The correspomnding binary sequence for each barcode value is
    %identified and fills the cell array
    for roll = 1:length(BarcodeNumberValues);
        BarcodeRow = str2double(BarcodeNumberValues{1,roll}) + 1;
        Pattern{1,roll} = code128B{BarcodeRow,3};
    end
    %The individual patterns are then converted into a single string
    PhrasePattern = strcat(Pattern{1,1:length(Pattern)});
end    

The intention of the function is to use an array of numbers, and convert them into a cell array of corresponding binary string values, then concatenate these strings. The error comes from line 11 column 26,

Pattern{1,roll} = code128B{BarcodeRow,3}; subscript indices must be either positive integers or logicals

Does this mean I can't create a cell array of strings..?

user2780519
  • 93
  • 1
  • 2
  • 8

2 Answers2

1

You can create a cell array of strings.

The problem in your code is that BarcodeRow is not a positive integer. Your input BarcodeNumberValues is likely the problem. Make sure it does not contain decimal values.

chappjc
  • 30,359
  • 6
  • 75
  • 132
1

As chappjc pointed out, the problem is probably that BarcodeNumberValues contains non-integer or non-positive values.

The following code tries to convert BarcodeNumberValues into an integer and aborts if it doesn't work.

[BarcodeRow, ~, ~, nextindex] = sscanf(BarcodeNumberValues{1,roll}, '%d', 1) + 1;
assert(nextindex == length(BarcodeNumberValues{1,roll}) + 1);
Konstantin
  • 2,451
  • 1
  • 24
  • 26