Reputation: 64
I have installed Matlab r2010a on my computer
I need to get the data from a XLSX named myExample
then verify if was processed before (it has to have certain number of columns). if was processed then do nothing. but if was not processed is required to delete the hearder row and several columns (overwrite the existing file).
Thanks a lot.
fname = 'myExample.xlsx'
values = {1, 2, 3, 4 ; 5, 6, 7, 8 ; 9, 10, 11, 12};
headers = {'First', 'Second', 'Third', 'Fourth'};
xlswrite(fname, [headers; values]);
First Second Third Fourth
1 2 3 4
5 6 7 8
9 10 11 12
Now I ask what you want to change into the file (Delete headers and some columns).
ColsDelete = {'B', 'D'};
After run the matlab script a verify if was prcessed or not and deleted the first row and column B and D. Now myExample.xlsx
contains:
1 3
5 7
9 11
This way is nice because you just put the columns you do not need
Upvotes: 0
Views: 2883
Reputation: 1623
Instead of deleting columns, would it not be more advisable to create a new xlsx file that contains just the data you need? I only suggest this because I too process many xls files and if I make a mistake in coding, i might lose data I didn't mean to delete (a simple off-by-one error might have you deleting all the columns you wanted to keep instead of the ones you wanted to throw away).
Use xlsread
to read from your original file fname.xlsx
and then use xlswrite
to write just the data you want to keep into another file fname_processed.xlsx
.
Upvotes: 1