any one know how i solve that the problem under the code

function varargout = cd(varargin)
% CD MATLAB code for cd.fig
% CD, by itself, creates a new CD or raises the existing
% singleton*.
%
% H = CD returns the handle to a new CD or the handle to
% the existing singleton*.
%
% CD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CD.M with the given input arguments.
%
% CD('Property','Value',...) creates a new CD or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before cd_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to cd_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help cd
% Last Modified by GUIDE v2.5 06-Apr-2018 21:48:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @cd_OpeningFcn, ...
'gui_OutputFcn', @cd_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
end
% --- Executes just before cd is made visible.
function cd_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to cd (see VARARGIN)
% Choose default command line output for cd
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes cd wait for user response (see UIRESUME)
% uiwait(handles.figure1);
end
% --- Outputs from this function are returned to the command line.
function varargout = cd_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
end
function pm_Callback(hObject, eventdata, handles)
% hObject handle to pm (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 pm as text
% str2double(get(hObject,'String')) returns contents of pm as a double
P_m=str2double(get(hObject,'String'))
% Save the new pm
handles.metricdata.pm = P_m;
guidata(hObject,handles)
end
% --- Executes during object creation, after setting all properties.
function pm_CreateFcn(hObject, eventdata, handles)
% hObject handle to pm (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function hc_Callback(hObject, eventdata, handles)
% hObject handle to hc (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 hc as text
% str2double(get(hObject,'String')) returns contents of hc as a double
P_HC=str2double(get(hObject,'String'))
% Save the new Phc
handles.metricdata.Phc = P_HC;
guidata(hObject,handles)
end
% --- Executes during object creation, after setting all properties.
function hc_CreateFcn(hObject, eventdata, handles)
% hObject handle to hc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function m_Callback(hObject, eventdata, handles)
% hObject handle to m (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 m as text
% str2double(get(hObject,'String')) returns contents of m as a double
M=str2double(get(hObject,'String'))
% Save the new M
handles.metricdata.m = M;
guidata(hObject,handles)
end
% --- Executes during object creation, after setting all properties.
function m_CreateFcn(hObject, eventdata, handles)
% hObject handle to m (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function power_Callback(hObject, eventdata, handles)
% hObject handle to 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 power as text
% str2double(get(hObject,'String')) returns contents of power as a double
P_CD_i = get(hObject,'String')
guidata(hObject,handles)
end
% --- Executes during object creation, after setting all properties.
function power_CreateFcn(hObject, eventdata, handles)
% hObject handle to power (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function k_Callback(hObject, eventdata, handles)
% hObject handle to k (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 k as text
% str2double(get(hObject,'String')) returns contents of k as a double
K=str2double(get(hObject,'String'))
K=handles.metricdata.m/handles.metricdata.m
%
% Save the new K
handles.metricdata.K = K;
guidata(hObject,handles)
end
% --- Executes during object creation, after setting all properties.
function k_CreateFcn(hObject, eventdata, handles)
% hObject handle to k (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function st_Callback(hObject, eventdata, handles)
% hObject handle to st (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 st as text
% str2double(get(hObject,'String')) returns contents of st as a double
Start_Time=str2double(get(hObject,'String'))
Start_Time_CD=Start_Time*60
% Save the new ST
handles.metricdata.ST = Start_Time_CD;
guidata(hObject,handles)
end
% --- Executes during object creation, after setting all properties.
function st_CreateFcn(hObject, eventdata, handles)
% hObject handle to st (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function reqtime_Callback(hObject, eventdata, handles)
% hObject handle to reqtime (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 reqtime as text
% str2double(get(hObject,'String')) returns contents of reqtime as a double
Required_time_CD=str2double(get(hObject,'String'))
% Save the new rt
handles.metricdata.rt = Required_time_CD;
guidata(hObject,handles)
end
% --- Executes during object creation, after setting all properties.
function reqtime_CreateFcn(hObject, eventdata, handles)
% hObject handle to reqtime (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function acct_Callback(hObject, eventdata, handles)
% hObject handle to acct (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 acct as text
% str2double(get(hObject,'String')) returns contents of acct as a double
Acc_ON_Time=str2double(get(hObject,'String'))
% Save the new rt
handles.metricdata.at = Acc_ON_Time;
guidata(hObject,handles)
end
% --- Executes during object creation, after setting all properties.
function acct_CreateFcn(hObject, eventdata, handles)
% hObject handle to acct (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
function cal_Callback(hObject, eventdata, handles)
% hObject handle to cal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%------------------Initial Data--------------------------------------------
WCDi=0;
DCDi=1;
Time=1;
End_time=60*24; %total simulation time (24 hours)
while Time<= End_time
%----------Cloth Dryer Model-------------------------------------------
%----------Deciding Status of the Cloth dryer--------------------------
if Time<handles.metricdata.ST
WCDi=0;
else if handles.metricdata.at<handles.metricdata.rt
WCDi=1;
else
WCDi=0;
end;
end;
%
P_CD = handles.metricdata.K*handles.metricdata.Phc*WCDi*DCDi+handles.metricdata.pm*WCDi; %#ok<*NASGU>
%
if WCDi==1 && DCDi==1
handles.metricdata.at=handles.metricdata.at+1;
end;
Time=Time+1;
end
P = handles.metricdata.K*handles.metricdata.Phc*WCDi*DCDi+handles.metricdata.pm*WCDi;
set(handles.P_CD_i, 'String', P);
end
command
Reference to non-existent field 'metricdata'.
Error in cd>cal_Callback (line 309)
if Time<handles.metricdata.ST
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in cd (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)cd('cal_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback

1 个评论

>> help cd
cd Change current working directory.
cd directory-spec sets the current directory to the one specified.
cd .. moves to the directory above the current one.
cd, by itself, prints out the current directory.

请先登录,再进行评论。

 采纳的回答

I do some edit on that if you can correct it i will be thankful

3 个评论

Most of your callbacks still assume that the structure has been been completely created. Your code is not enabling and disabling buttons according to which elements of the structure are known to have been set, so a user can trigger a use of a field before the field is set. Remember, if the user can click the gui elements in an unexpected order then some user will do so.
sorry but i don't know how to correct that
In clothd_OpeningFcn add
handles.metricdata = struct('at', datetime(), 'K', 1, 'm', 0, 'Phc', 17, 'pm', 0.82, 'rt', datetime(), 'ST', datetime() );
before the "% Update handles structure"
Adjust these values to be sensible initial values for your purposes.
I recommend you also have another look at k_callback which currently has
K=str2double(get(hObject,'String'))
K=handles.metricdata.m/handles.metricdata.m
The first of those lines gets a number from a string, but the second of the lines overwrites that number with a value that is going to be either 1 (nearly all values) or nan (if the .m happened to be 0 or nan)

请先登录,再进行评论。

更多回答(1 个)

You never called st_Callback so handles.metricdata.ST never got assigned before you tried to use it.
Plus, you called your GUI "cd" which is a horrible idea because that is a built-in function and you should not name your own functions after built-in reserved functions.

3 个评论

could you correct the error because its my first time in gui
Maybe later tonight. I'm off to explore Singapore now. Attach your .fig file, and your .m file with the paper clip icon.
In cd_OpeningFcn you need to assign a structure to handles.metricdata that has all of the fields that you are going to use . I say all of them because absolutely nothing in your code checks whether the various metricdata fields exist before going ahead and using them, so you need to assign usable defaults to every field before the user is permitted to interact with the GUI.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by