0

What I'm attempting to do is simple: Given an excel dataset and user defined inputs, open the associated excel file, pull the associated information for the user inputted information and save this information in a separate excel file.

I've already developed a list of values and the program recognizes user input with associated checks. I'm stuck on getting Matlab to use this information to open the correct dataset, I don't know how to get Matlab to pull a row/column in excel with a silent open and I don't know how to get it to save that data into a separate excel file. Any help would be appreciated, thank you.

1 Answer 1

1

Consider using the functions readtable, and writetable if you have a recent MATLAB (anything more recent than R2013b). The readtable function will 'silently' read data from a specific worksheet in an Excel file into a MATLAB table variable. From there you can 'query' the table to find the specific rows you want and write the result to a new excel table with writetable.

Using readtable, you can specify the range of data with the parameters sheet and range.

requested_data = readtable(excel_file, ...
    'sheet',input_sheet_name, ...
    'range',input_data_range);

and write the data to another Excel file with

writetable(requested_data,ouput_excel_file, ...
'sheet',output_sheet_name, ...
'range',output_data_range);

Note: Remember to set the values for excel_file, input_sheet_name, input_data_range, output_excel_file, output_sheet_name, and output_data_range before running above commands.

Querying the table to access data in your table. One way would be to use ismember as in this answer.

Finally, use writetable to store the values.

See also: sheetnames, detectImportOptions, and SpreadsheetImportOptions

Sign up to request clarification or add additional context in comments.

6 Comments

Is there a way to associate a value lookup with read table?
@aaron: Can you define what you mean by "associate a value lookup"? or explain the process you want?
Similar to vlookup in excel. I'm looking to take an input, open the excel file, find the correlating cell to the input and then pull the associated data for that input from another cell.
@aaron see my edits to this answer. If they don't answer your queestion maybe refocus the question to be a bit more specific with regard to what you are trying to do what 'errors' you are encountering in your code.
I got another question regarding this. I'm attempting to read across columns as the input fields I created will put them horizontally into the table (i.e. A1 = CO, B1 = NO, C1 = NO2). I'm attempting to do a while function loop on this so that it will run multiple iterations where it will read A1, run the script using CO as the input and then rerun it with B1. What would be the while command? I attempted While c_locations_of_interest(1,i) ~= "" where c-Locations_of_interest is a user defined table with only inputs in the columns of the first row..
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.