I'm working with image files which are all labeled something like "152b_800_1000_Ti.psd". [Name_Temp_Time_Element"]
I am going to use the RGB data for graphing, and I would like to automatically add labels to each graph containing the "Name" "Temp" "Time" and "Element" taken from the images' filenames. The code beneath is essentially one part of the whole puzzle, to gather the text for each label from the file names.
This should work to
- return the files' data from a folder, through the dir function
- strip the names with fileinfo.name
- break up the filenames (which include extensions and such) into Path, Name and Extension arrays with fileparts
- cycle through each Name (in the fname[] array) and break it up further into Sample, Temp,Time and Element using the strsplit function and a '_' delimiter.
fileinfo = dir('C:\Users\...\MATLAB Drive\...\Images');
fdata = {fileinfo.name};
fname={};fext={}; fpath={}
for i=1:size(fdata,2)
[filepath,filename,fextension] = fileparts(fdata(i));
fpath{i}=filepath;
fname{i}=filename;
fext{i}=fextension;
end
clear filepath filename fextension
Sample={}; Temp={}; Time={}; Elem={};
for i=1:size(fname,2)
N = strsplit(fname{i},'_');
Sample{i}=N(1);
Temp(i)= N(2);
Time(i)=N(3);
Elem(i)=N(4);
end
The problem I am encountering is that
returns
and I am not sure how to remove those first 3 columns. I have noticed that the MATLABDRIVE file is craeted everytime I start Matlab.
I have tried to simply delete those cells but it seems that the first one cannot be removed no matter what.
So, why does fileinfo.name return those first 3 columns, and how can I get rid of them?
Also, when running the entire thing, I get this error below.
Index exceeds the number of array elements (1).
Error in test (line 29)
Temp(i)= N(2);
Even though,
returns properly.
ans =
1×4 cell array
{'153c'} {'800'} {'1000'} {'Ti'}
Thus, it appears that it is not properly assigend to the N variable.
I'm pretty sure my shoddy understanding of cells v arrays might be the issue here.