xls import data from gui browse button selection
Show older comments
i have created a gui with a browse button to select a file. I then want this file to have the data imported. I created a static text box to show the file pathway of the selected folder and this works fine. I then created code (auto generated) for importing the data in a seperate m file and it worked perfectly specifying the file name. I then put this code into my main m file w the GUI and changed the filename to set(handles.text2_filename,'String',filename)but it doesn't automaticall carry out the calculations above that unless i put a breakpoint. How do i get the variables to appear in the workspace when the file is selected.
My code for importing data is as follows:
sheetName='Data';
[numbers, strings] = xlsread((set(handles.text2_filename,'String',filename)), sheetName);
if ~isempty(numbers)
newData1.data = numbers;
end
if ~isempty(strings) && ~isempty(numbers)
[strRows, strCols] = size(strings);
[numRows, ~] = size(numbers);
% Break the data up into a new structure with one field per row.
if strCols == 1 && strRows == numRows
newData1.rowheaders = strings(:,end);
end
end
% Create new variables with custom names
% in the base workspace from those fields.
for i = 1:size(newData1.rowheaders, 1)
assignin('base', genvarname(newData1.rowheaders{i}), newData1.data(i,:));
end
Accepted Answer
More Answers (0)
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!