Filter löschen
Filter löschen

i have error what is a solution ?

18 Ansichten (letzte 30 Tage)
N Y
N Y am 7 Jul. 2017
Bearbeitet: Walter Roberson am 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 Kommentare
Walter Roberson
Walter Roberson am 7 Jul. 2017
You do not assign to modelname in what you show
Geoff Hayes
Geoff Hayes am 7 Jul. 2017
Where is modelname defined?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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'

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by