필터 지우기
필터 지우기

Please help me fix my code!

조회 수: 2 (최근 30일)
Rosie
Rosie 2012년 8월 2일
답변: DEWDROP 2020년 3월 13일
Hi Everyone,
I want to be able to refer to the information of my edit box (called edit_x) throughout my GUI's m file. My code is quite complicated. The idea is that whatever the user enters into the edit box is compared with the already loaded .mat files listed in the listbox (called listbox_x), and only those whose first n letters match those of the characters enterred by the user into the edit box will remain in the list box.
However, every time I try it out, it tells me that my edit_x is undefined.
If anyone could give me any guidance on this I would be extremely grateful.
Thanks,
Rosie
For reference, and to identify if I've done anything else wrong that's caused this error, I'll post my code below;
% --------------------------------------------------------------------
function varargout = listbox_x_CreateFcn(h, eventdata, handles, varargin)
D = dir('*.mat'); %Scan directory for .mat files
listbox_x_string = {D(:).name}; %Set to display full name of files found
set(h,'String',listbox_x_string); %Display list of files in ListBox_x
guidata(gcbo,handles)
% --------------------------------------------------------------------
function varargout = edit_x_Callback(h, eventdata, handles, varargin)
edit_x_string = varargin{1};
handles.edit_x_string = edit_x_string;
guidata(gcbo,handles)
% --------------------------------------------------------------------
function varargout = listbox_x_Callback(h, eventdata, handles, varargin)
listbox_x_oldstr = get(h,'String');
n = length(edit_x_string);
match_x = strncmpi(handles.edit_x_string,listbox_x_oldstr,n);
if n >= 1
if match_x == 0
set(h,'String',' ');
elseif match_x >= 1
set(h,'String',listbox_x_oldstr(match_x));
end
end
guidata(gcbo,handles)

채택된 답변

Rosie
Rosie 2012년 8월 2일
In case anyone has the same issue I managed to fix the code by changing it to the following;
% --------------------------------------------------------------------
function varargout = listbox_x_CreateFcn(h, eventdata, handles, varargin)
D = dir('*.mat'); %Scan directory for .mat files
listbox_x_string = {D(:).name}; %Set to display full name of files found
set(h,'String',listbox_x_string); %Display list of files in ListBox_x
guidata(gcbo,handles)
% --------------------------------------------------------------------
function varargout = edit_x_Callback(h, eventdata, handles, varargin)
edit_x_string = get(h,'String');
guidata(gcbo,handles)
D = dir('*.mat');
listbox_x_string = {D(:).name};
match_x = strmatch(edit_x_string,listbox_x_string)
set(handles.listbox_x,'String',listbox_x_string(match_x))
guidata(gcbo,handles)

추가 답변 (1개)

DEWDROP
DEWDROP 2020년 3월 13일
PLEASE HELP TO FIX LINE mdl .
clear
D =[8.3, 4.76, 4.79, 4.24, 3.69]; %m^2/s
t =[91, 180, 365, 730, 1095]; %days
Dref =D(1);%m^2/s
tref =t(1); %days
x=log((tref./t));
y=log((D./Dref));
mdl= fitlm(x,y,'y~x1-1');%linear regression formula
figure(1)
plot(mdl)
xlabel('ln(t_ref/t)')
ylabel('ln(D/D_ref)')
title('m calculation')
grid on
m = table2array(mdl.coefficients(1,1));
time=linspace (0,100,10000)
for i=1:length(time)
Dt(i,1)=Dref/(1-m).*(tref/365/time(i)).^m;
ke=1;
kt=1;
At(i,1)=(tref/365./time(i)).^m;
Dappc(i,1)=ke*Dref*kt*At(i,1);
end
figure(2)
ACI=loglog(time,Dt*365*24*60*60,'r','linewidth',2)
fib=loglog(time,Dappc*365*24*60*60,'m','linewidth',2)
xlabel('time,year')
ylabel ('diffusion coefficient,m^2/s')
ylim([10^-5,10^-2])

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by