How to link simulink with GUI whith used matlab function
1 view (last 30 days)
Show older comments
Hello. Please help me understand what I'm doing wrong. I have a simulating model. I pass data to the matlab function. I put them on the plot. I need to make checkboxes that turn lines on and off on the plot.
I write like this:
function GuiCheckVisible(PlotName, TextChBox, PositionCh)
coder.extrinsic('uicontrol');
% [Ncount, ~] = size(PlotName);
ChGui = zeros(2,1); % checkbox handle (preallocate)
for i = 1:2
ChGui(i) = uicontrol('Style','checkbox','Value',1,...
'Position',PositionCh{i},'String',TextChBox{i});
end
set(ChGui,'Callback',{@box_value,ChGui,PlotName});
%-----
function box_value(hObj,~,uiG, pn) %#ok<*INUSL
% Called when boxes are used
v = get(hObj,'Value');
Ind = uiG==hObj;
%[axes visibility]:
s = {'off','on'};
%[line visibility]:
hl = findobj(pn(Ind),'Type','line'); % line handles
set(hl,'Visible',s{v+1});
end
end
In matlab function :
pRts = plot(TimePointArr, tRange);
pRt = plot(TimePoint, Rt);
GuiCheckVisible([pRts; pRt],{'graf1', 'graf2'},{[10 1 100 20], [110 1 100 20]});
In matlab all works, but in the Simulink I have:
Code generation does not support mxArrays inside cell arrays. Function 'GuiCheckVisible.m' (#391.341.368), line 11, column 22: "{@box_value,ChGui,PlotName}" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'SubVis 5.3/FncTableResult' (#143.2071.2162), line 55, column 5: "GuiCheckVisible([pRts; pRt],{'False alarm', 'True target'},{[10 1 100 20], [110 " Launch diagnostic report.
0 Comments
Answers (1)
Abhaya
on 19 Dec 2024
Hi Marina,
The error you're encountering occurs because Simulink's code generation does not support 'mxArray' Data in a Cell Array.
In the code, when you provide the function handle in a cell array, MATLAB treats it as ‘mxArray’, which is not supported for code generation, especially when it comes to generating plots or passing the handles.
To visualize the plots you can use Simulink ‘Scope’ block.
Please refer to the MATLAB documentation for scope block given below.
For more information of cell array restrictions, please refer to following MATLAB documentation.
0 Comments
See Also
Categories
Find more on Simulink Functions 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!