use a text from a text box in a GUI
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I'm doing a GUI in which the user has to enter a name of a series of files that is sequential, and I don't know how to use the information in the Text.edit to search for the files in a for cicle... here is the code im using... thank you very much for your help
NM=str2double(get(handles.NM,'String')); %number of files
Especie=get(handles.Especie,'String'); % first part of the name
assignin('base','Especie',Especie)
Fecha=get(handles.Fecha,'String');% second part of the name
assignin('base','Fecha',Fecha)
Hora=get(handles.Hora,'String');% third part of the name
assignin('base','Hora',Hora)
for k=1:NM
eval(['load Medicion_Carne_',num2str(k),'_',Especie,'_',Fecha,'_',Hora,'.mat']);
end
0 个评论
采纳的回答
Image Analyst
2020-4-2
编辑:Image Analyst
2020-4-2
To get a string from an edit text box don't use the old obsolete get(), use the new OOP style:
Especie = handles.Especie.String; % Get the first part of the name from the edit text box.
Fecha = handles.Fecha.String; % Get the second part of the name from the edit text box.
Hora = handles.Hora.String; % Get the third part of the name from the edit text box.
Never use eval() or assignin(). See the FAQ: FAQ : How_can_I_share_data_between_callback_functions_in_my_GUI?
folder = pwd; % or 'C:/your data' or wherever...
for k = 1 : NM
baseFileName = sprintf('Medicion_Carne_%d_%s_%s_%s.mat', k, Especie, Fecha, Hora);
fullFileName = fullfile(folder, baseFileName); % Prepend folder
if isfile(fullFileName)
% Load this .mat file's variables into a stored structure.
% It's in a cell array so as to not overwrite any other filenames that will also get loaded.
fprintf('Loading mat file: %s\n', fullFileName);
s{k} = load(fullFileName)
else
warningMessage = sprintf('Warning:\n%s\ndoes not exist', fullFileName);
uiwait(warndlg(warningMessage));
end
end
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!