MATLAB: How can write names of image / file in excel sheet using matlab

excelexporting excel data

I need to print name of an image or current browsed file in specific position in excel using matlab Here is the code of what I tried so far
Image2 = imread('D:\ahmed','jpeg');
xlswrite('D:\aa.xls',image2,'Sheet1','A1');
OR ..
when i need to print name of browse image in GUI .. how can i print name of this upload image in excel sheet …
filename=handles.filename;
[X2] = imread(filename);
xlswrite('D:\aa.xls',[X2],'Sheet1','A1');
both codes don't write the name of image … its give me name of variable (image2 or X2 ) and do not write name of image ahmed or name of image in X2 which i browsed … any help please .
hope to get the following output :
excel sheet1 cell [A1] contain (( name of my image or browsed image name like wilyam or browsed image name ).

Best Answer

I think this should cover whatever case you want to do. It writes out both the filename string into cell A1, and the full uint8 numerical array into a bunch of cells with the upper left corner at cell A2 of the worksheet:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'D:\ahmed'; % Specify where starting folder is that the user starts browsing from..
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
% Read in the file into a variable called X2.
[X2] = imread(fullFileName);
imshow(X2, []);
drawnow;
% Construct the output workbook name.
excelFullFileName = fullfile(pwd, 'aa.xlsx');
% Now write out the filename string to cell A1 of a workbook called aa.xlsx.
% fullFileName needs to be put into a cell otherwise it will put one character
% of the filename into each cell along row 1 of the worksheet.
% To put into a cell, wrap the fullFileName variable in braces.
xlswrite(excelFullFileName, {fullFileName}, 'Sheet1', 'A1');
% Next write out the actual image array to cell A2 of a workbook called aa.xlsx.
% This takes a long time so be patient.
xlswrite(excelFullFileName, X2, 'Sheet1', 'A2');
% Launch Excel opened to this workbook.
winopen(excelFullFileName);