How to link simulink with GUI whith used matlab function
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Abhaya
2024년 12월 19일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!