How do I use the names of images ( .png's) in my folder to transfer over as column headings in a csv?
조회 수: 1 (최근 30일)
이전 댓글 표시
Greetings, I am looking for guidance to help me understand how to use the names of my hyperspectral images (.png) from a folder as column headings on a CSV to make sure the wavelength associated to a value is from the correct image (as a double check). As an example, if I have these images: 0_0_0.png, 2_0_0.png,.... 244_0_0.png, how can I have the same name transfer over to a csv?
I used 'strsplit()' to break up the folder name so parts of the folder would be included in the CSV but I am not sure what else I need.
Thank you
Folder name Example: 1-4-17_14-02-TL-C-A-1_2017-01-04_RaePond
fields = strsplit(directoryname,'_'); %breaks up main folder name
barcodeString = fields{2}; %barcode
dateString = fields{3}; %date (there are multiple dates)
fileName = fullfile(pwd, 'Hyper_Results.csv'); %csv file name containing all of the results
fid = fopen(fileName, 'wt');
fprintf(fid, 'barcodeString, dateString\n');
% Write headers
fprintf(fid, '%s, %s, %f, %f\n', barcodeString, dateString, "insert .png names");
fclose(fid);
댓글 수: 2
Paolo
2018년 5월 24일
편집: Paolo
2018년 5월 24일
files = dir ('*/*.png')
will list all the .png files under the current directory (including subfolders). You can then access the name of the files with:
files.name
I suggest you use Stephen's filename sorting function is you wish to read the files in a certain order.
I also noticed that in your code you are using 'pwd' when calling fullfile function, meaning that the code will fail to open the .csv file if your working directory changes. I recommend using an absolute path for the .csv file.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!