Struct Object definition in Simulink User Defined Functions and Preallocation of Struct Objects
1 view (last 30 days)
Show older comments
Hello,
My overall goal is to read images into simulink at a fixed rate. These images are being captured by third party software in real time and saved in a folder. It is Simulink's task to read the latest image and do computations on it. I am currently using the user-defined Matlab function block in Simulink to do the task.
I have tried various things, but I am having a hard time wrapping my head around the struct and extrinsic commands. I understand that you have to predefine the struct variables for the memory allocation. And I understand that when you run a function in extrinsic mode, the output is an mxArray. What I don't really get is how to convert the mxArray to the struct object and how to properly use it.
The code below gives me an error of: "Size mismatch for MATLAB expression 'struct.name'. Expected = 1x4 Actual = 1x14 Block MATLAB Function (#24) While executing: none ". Which essentially means that the struct command assigns the string "char" to the "name" field.
What is the proper way of preallocating a struct object, or converting it from mxArray to struct? Also, will there be issues with the varying size of the 'name' entry when during preallocation?
if true
% code
function y = read_Image() %#codegenn
coder.extrinsic('imread');
coder.extrinsic('dir');
coder.extrinsic('pause')
dirinfo=struct('name','char','date','char','bytes',double,'isdir','logical','datenum','double' );
dirinfo=(dir('testfolder\\*.png'));
y=(zeros(267,327,3,'uint8'));
y = imread(['testfolder\\',dirinfo(end).name]);
pause(0.25)
end
Cheers,
0 Comments
Answers (0)
See Also
Categories
Find more on String 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!