I want transmit an image using Simulink and USRP. I have the following code %if true function msg = genMsg persistent imgmatRows imgmatCols imgvec msgBin msgBinRows msgBinCols msgTmp; coder.extrinsic('imread'); if isempty(imgvec) imgmat = imread('cameraman.tif'); [imgmatRows, imgmatCols] = size(imgmat); imgvec = reshape(imgmat, 1, imgmatRows * imgmatCols); msgBin = de2bi(int8(imgvec), 7, 'left-msb'); [msgBinRows, msgBinCols] = size(msgBin); msgTmp = reshape(double(msgBin).', msgBinRows*msgBinCols, 1); end msg = msgTmp;
When I run this code it produces the following error message:
"Function output 'msg' cannot be an mxArray in this context. Consider preinitializing the output variable with a known type."
How can I fix this problem?
No products are associated with this question.
You are calling imread extrinsically and it will return a variable of type mxArray back to the MATLAB function. This cannot be done since Simulink cannot use mxArray datatypes.
To fix this, define imgmat as a double before calling imread like this:
imgmat = zeros(pixelwidth,pixelheight,cdata); imgmat = imread('cameraman.tif');
That will force the coder to generate imgmat as a type double. When you call imread it will store the result in a double. You will also need to know the size of the image before running this as the result will be placed in a defined matrix. I would run the imread in MATLAB first to determine what imgmat should be defined as.
Play games and win prizes!Learn more