How to do a code optimization for data export/import to uielements
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a gui with a uitable with a maximum of 30 rows and 30 edit-boxes. I what 2 specific things. 1) Export the cell array with the uitable strings (4 columns and 1–30 rows). Then I want the values of the 30 edit-boxes inserted in the cell array in column 5. 2) Finally I want to be able to load the exported cell array; the 4 first columns into the uitable and the 5th column into the edit-boxes. The code I have created (see below) is exporting/importing an excel sheet but it is very slow, even with only 5–7 rows in the uitable. How can I make this faster and more elegant. I doesn’t have to be an excel sheet. It can be a *.txt, *.cvs or something else (not *.mat).
% --- Dataset example
GUIstate = {
'REF20171002-2.txt' 'REF20171002-2' '217096907-1.txt' [217096907] [1]
'REF20171002-4.txt' 'REF20171002-4' '217096909-1.txt' [217096909] [3]
'REF20171002-4.txt' 'REF20171002-4' '217096911-1.txt' [217096911] ''
'REF20171002-4.txt' 'REF20171002-4' '217100125-1.txt' [217100125] [5]
'REF20171002-4.txt' 'REF20171002-4' '217100141-1.txt' [217100141] ''
}
% --- Save GUI state on pushbutton324.
function pushbutton324_Callback(hObject, eventdata, handles)
Folder=handles.Folder;
data = get( handles.uitable1, 'data');
data2 = data(:,[1:4]);
data3 = data2(~all(cellfun('isempty', data2(:, 3)), 2), :);
[r c]=size(data3);
num=r;
adj=cell(num,1);
for i = 1:num
adj{i,1}=get(handles.(sprintf('edit%d',i)),'String');
end
data3(:,5)=adj;
[filename, pathname] = uiputfile(fullfile(Folder, '*.xls'),'Save GUI file as');
newfilename = fullfile(pathname, filename);
xlswrite(newfilename,data3);
% --- Load GUI state on pushbutton325.
function pushbutton325_Callback(hObject, eventdata, handles)
Folder=handles.Folder;
[filename, pathname] = uigetfile(fullfile(Folder, '*.xls'));
newfilename = fullfile(pathname, filename);
[~, ~, data] = xlsread(newfilename,'Sheet1');
set( handles.uitable1, 'Data', data(:,1:4));
conc=data(:,5);
[r c]=size(data);
num=r;
for k = 1:num;
if isnan(conc{k})
conc{k} = '';
end
end
for i = 1:num
set(handles.(sprintf('edit%d',i)),'String',conc{i,1});
end
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!