How can I pass a Figure Handle to Matlab code embedded in Simulink, and capture that plot as an Image in the loop?
10 次查看(过去 30 天)
显示 更早的评论
Hi all,
I'm working on a Simulink model that updates a plot every time step of the model. The plotting is done within an embedded Matlab function. I can make this work for a generic figure that I call in the basic 'figure(1); plot(x, y)' sense, but ideally I'd like to be able to pass a figure handle to the embedded Matlab function, so that I can create the figure with specific properties when I initialise the model, then plot it to directly, but I get errors whenever I try. Are figure handles just completely unsupported by embedded Matlab functions or is there a way to do this? I'm sure this used to work back when figure handles were just doubles, but now they are objects Simulink doesn't seem able to do this anymore.
Further to this, I would then like to capture this plotted image as an image matrix for further processing. Usually I would do this with the 'getframe' function, but I get an error that says the function is unsupported for code generation. Does anyone have a workaround? Any help would be greatly appreciated.
Many thanks, Chris
0 个评论
回答(2 个)
Nick Choi
2017-11-17
编辑:Nick Choi
2017-11-17
If you are planning to generate code from the Simulink model, you will not be able to use the 'plot' function because it is not supported for code generation. The following documentation page contains the list of functions supported for C/C++ code generation:
According to this documentation page, passing function handles to extrinsic MATLAB functions is not supported for code generation:
If you want to perform post-simulation data processing, I would suggest logging the data from the model and plotting it from within the MATLAB environment.
0 个评论
Faiza Bukenya
2017-12-9
try this out,it worked for me. F = getframe(a); % a is your figure currently displaying your image with the rectangle % vessel_pericyte = F.cdata; hold off figure,imshow(a);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!