MATLAB: Excel writing Problem: find correct row, write to empty cell

excelgui

Hello Community,
I have a fairly advanced excel writing task. I have 2 types filenames that I need to write to specific cells in a spreadsheet. I acquire these names from user selection in a GUI. The files are named in this fashion: Label_SLR_LL_S1_0006_v1
Segment_SCH_RL_S3_0008_v1
So the files with "Label" are written to the Label and column and so forth.
First problem is I need to write to the next empty row instead of overwriting existing data. Ideally, I would like to check to see if the data already exist in the column, if it does, overwrite, if not find empty cell and write.
The second problem is the sheet contains data that is organized by row in this fashion:
2009-10-06 09-26-15_SHC_RL_S1_0002FinalData.mat
2009-10-06 09-28-01_SHC_RL_S2_0002FinalData.mat
2009-10-06 09-37-31_SHC_LL_S1_0002FinalData.mat
2009-10-06 09-39-18_SHC_LL_S2_0002FinalData.mat
2009-10-06 09-48-43_RHA_RL_S2_0002FinalData.mat
2009-10-06 09-50-06_RHA_RL_S3_0002FinalData.mat
2009-10-06 10-09-46_SLR_RL_S1_0002FinalData.mat
So the keywords are
SLR_LL_S1
SHC_LL_S2
RHA_RL_S3
and so forth Each row in the the sheet contains data specific to that identifer. I need to be able to write my filenames:
Label_SLR_LL_S1_0006_v1
Segment_SCH_RL_S3_0008_v1
into the correct row based on the keywords.
The second part of my problem might not be necessary if a simple sort in excel can put my filenames in the correct order? I dont think it can because of how they are named.
I realize this a hefty question and any suggestion are greatly appreciated. I litteraly spent over 3 hours searching the Answers and newsgroup but couldt find a solution to this problem.

Best Answer

There are still things you didn't clarify. The data in the column "Header", are there multiple lines of file name that contain the same key? If not,, the following code should be good enough.
NewFileName='Label_SLR_LL_S1_0006_v1';
if strfind(NewFileName,'Label_')
Column=2;
Key=NewFileName(7:16);
elseif strfind(NewFileName,'Segment_');
Column=3;
Key=NewFileName(9:18);
else
error('Wrong File Name.');
end
ExcelFile='MyData.xls';
[Dummy,Dummy,Raw]=xlsread(ExcelFile);
Index=strfind(Raw(:,1),Key);
Index=find(~cellfun('isempty',Index));
Raw{Index,Column}=NewFileName;
xslwrite(ExcelFile,Raw);