i have error what is a solution ?

17 views (last 30 days)
N Y
N Y on 7 Jul 2017
Edited: Walter Roberson on 7 Jul 2017
this is part of my code
function TV_power_Callback(hObject, ~, handles)
% hObject handle to TV_power (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of TV_power as text
% str2double(get(hObject,'String')) returns contents of TV_power as a double
handles=guidata(hObject);
a= get(handles.TV_power,'string');
val= str2num(a);
s=val/0.85;
set_param(handles.tv,'ActivePower',num2str(s));
guidata(hObject,handles);
function load1_Callback(hObject,evendata, handles)
% hObject handle to load1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
modelname=get(handles.after,'string');
if isempty(modelname)
errordlg('You have not input the model name');
end
checkload=~isempty(find_system('type','block_diagram','name',modelname));
if checkload==0
try
load_system(modelname);
catch
end
end
block_tv=sprintf('%s/tv',modelname);
block_tv=sprintf('%s/tv',modelname);
tv=get_param(block_tv,'ActivePower');
set(handles.TV_power,'string',num2str(tv));
handles.modelname=modelname;
handles.block_tv=block_tv;
guidata(hObject,handles)
function varargout =gui_edit(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_edit_OpeningFcn, ...
'gui_OutputFcn', @gui_edit_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before gui_edit is made visible.
function gui_edit_OpeningFcn(hObject,evendata, handles, varargin)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = gui_edit_OutputFcn( hObject, eventdata,handles)
varargout{1} = handles.output;
% --- Executes on button press in RUNA.
function RUNA_Callback(hObject, eventdata, handles)
% hObject handle to RUNA (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set_param('finalStateflowDrH','SimulationCommand','Start');
Error in
>> gui_edit Error using gui_edit>load_Callback (line 566)
'File Name' is not a valid model name because it is not a valid MATLAB function name.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in gui_edit (line 18)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui_edit('load_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  4 Comments
Walter Roberson
Walter Roberson on 7 Jul 2017
You do not assign to modelname in what you show
Geoff Hayes
Geoff Hayes on 7 Jul 2017
Where is modelname defined?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Jul 2017
You have
checkload=~isempty(find_system('type','block_diagram','name',modelname));
if checkload==0
try
load_system(modelname);
catch
end
end
Suppose the model is not found, then find() returns empty, isempty() returns true, the ~ returns false, which is the condition to try to load the subsystem. Suppose that fails, then the catch is invoked which gracefully does nothing. Then the code continues on and tries the use the model even though loading failed.
However, look at
function load1_Callback(hObject,evendata, handles)
>> gui_edit Error using gui_edit>load_Callback (line 566)
Notice that the error is in load_Callback, which is a routine that you do not show us -- you show us load1_Callback
Also your message
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui_edit('load_Callback',hObject,eventdata,guidata(hObject))
can only occur when loading the .fig file, upon encountering a CreateFcn callback which is something you should not have configured.
So it appears to me that you have configured a callback to run before the user has entered any value into handles.after and that your initial setting for that is 'File Name', and then your code fails to pay attention to a problem in loading a model named 'File Name'

More Answers (0)

Categories

Find more on Data Type Identification in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!