MATLAB: Can user choose desired column data from excel to matlab

columnexcelimport dataselect data

Hi all!!
I want by clicking BROWSE button (GUI) choose the file (I'm going to do this be uigetfile() ), open it and select the column (for example A2:A50) to be importing to matlab as a X vector.
How to do this?
Thanks in advance!

Best Answer

Well I imagine the user needs to see the data before making the decision about which column to import. So they either do that in Excel in advance and then you ask them in MATLAB, or you haul the whole workbook into MATLAB and display in a uigrid control and then ask them. You can ask them via inputdlg(), like this snippet:
% Ask user for a number.
defaultValue = 45;
titleBar = 'Enter a number';
userPrompt = 'Enter the column number';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
integerValue = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(integerValue)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
integerValue = defaultValue;
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', integerValue);
uiwait(warndlg(message));
end
If they enter column letters, you'll need to use this: http://blogs.mathworks.com/pick/2010/04/16/from-excel-column-labels-to-numbers/