Unable to save an Excel file as a csv type file to specific subfolder
Afficher commentaires plus anciens
using Matlab2012a and I am trying to open an excel file, convert to csv and then save the csv file with a new name to a specific subfolder. I am able to open the excel file, convert to csv type and rename...but unable to save the csv file to the subfolder of my choosing. MATLAB defaults saving the file to the highest level folder in the path which is a folder named 'BCIS'. I want to save it to the subfolder 'subFolder1a'
The code I'm using is as follows: ...
% reading excel and convert to cell array
[~,readfile,~] = xlsread([FilePath FileName]);
Tfile = readfile(2:end,2);
[nrows,~]= size(Tfile);
% create dialogue box for user entered file name to save
dlg_title = 'Save Txt File';
num_lines = 1;
def = {''};
answer = inputdlg('Please enter a name to save file:',dlg_title,num_lines,def);
% Convert file to csv
filename = (answer{1,1});
fid = fopen(filename, 'w');
for row=1:nrows
fprintf(fid,'%s', Tfile{row,:})
end
fclose(fid)
% save file to subfolder
FilePathText = 'C:\BCIS\subFolder\subFolder1\SubFolder1a\';
filename = uiputfile({'*.csv','Data Files (*.csv)'},...
'Save Ticker List As',...
[FilePathText filename]);
Any help greatly appreciated.
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 28 Déc 2013
You need to get the folder from uiputfile() then call fullfile() to combine them and finally call csvwrite:
[baseFileName, folder] = uiputfile(.............whatever....
fullFileName = fullfile(folder, baseFileName);
csvwrite(fullFileName, yourMatrix);
Then if you're going to do that you don't need all the prior stuff about using fprintf() to write it since csvwrite() will do that anyway.
1 commentaire
Carlos Freyre
le 28 Déc 2013
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!