I have a function that lets say can have an output of variable size array between 1 and 10 elements I have set y as variable size as [1,10] in the Edit Data window The code in if 0 … works correctly and return variable size arrays of size 9 or 10 When I try to run code above if 0 i get (initially was commented)
Size mismatch (size [0 x 0] ~= size [1 x 2]).The size to the left is the size of the left-hand side of the assignment.Function 'FrameGenerator/AddEscapeCharacter1/MATLAB Function' (#23.281.291), line 9, column 3:"finalArray"
How to fix this lol ?
Here is the code
function y = addEscapeCharacter(frameBytes, escapeCharacter, startOfFrame) %codegen
finalArray = single([]);%coder.varsize('y',[1,10]);
for i =1:length(frameBytes) currentFrameByte = frameBytes(i); if currentFrameByte == escapeCharacter || currentFrameByte == startOfFrame finalArray = horzcat([escapeCharacter,frameBytes(i)], finalArray); else finalArray = horzcat([currentFrameByte], finalArray); endendif 0 if randi(2) ==1 finalArray = horzcat(single( [1 2 3 4 5 6 7 8 9]) , single([6])); else finalArray = horzcat(single( [1 2 3 4 5 6 7]), single([6]), single([1])); endend%print('%d', length(finalArray));
y = single(finalArray);
Best Answer