Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 696501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:04:12+00:00 2026-05-14T03:04:12+00:00

I am reading a .xls file and then procesing it inside and rewriting it

  • 0

I am reading a .xls file and then procesing it inside and rewriting it in the end of my program. I was wondering if someone can help me to parse the dates
as my input file name is like file_1_2010_03_03.csv

and i want my outputfile to be

newfile_2010_03_03.xls

is there a way to incorporate in matlab program so i do not have to manually write the command
xlswrite(‘newfile_2010_03_03.xls’, M);
everytime and change the dates as i input files with diff dates
like
file_2_2010_03_04.csv.

Maybe i was not clear>
I am using uigetfile to input 3 diff files in format
file_1_2010_03_03.csv,file_2_2010_03_03.csv,file_3_2010_03_03.csv

Now i am processing the file inside my program and writing 4 output files
with names newfileX_3_2010_03_03.xls,newfileXY_3_2010_03_03.xls,newfileXZ_3_2010_03_03.xls,
newfileYZ_3_2010_03_03.xls

so my dates are not current date , but i need that from the input file and append that to newname for my xlswrite.

so was wondering if there is a way i can write a generic

xlswrite (‘xxx ‘ M);
which will pick the name i want instead of me having 2 modify the name’ xxx’ everytime i input a new file

Thanks

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:04:12+00:00Added an answer on May 14, 2026 at 3:04 am

    It looks like I misunderstood what you meant with ‘file_1’, ‘file_2’ – I thought the numbers 1 and 2 had some kind of importance.

    oldFileName = 'something_2010_03_03.csv';
    %# extract the date (it's returned in a cell array
    theDate = regexp(oldFileName,'(\d{4}_\d{2}_\d{2})','match');
    newFileName = sprintf('newfile_%s.xls',theDate{1});
    

    Older Version with Explanations

    I assume that the date in all your files is the same. So your program would go

    %# load the files, put the names into a cell array
    fileNames = {'file_1_2010_03_03.csv','file_2_2010_03_03.csv','file_3_2010_03_03.csv'};
    
    %# parse the file names for the number and the date
    %# This expression looks for the n-digit number (1,2, or 3 in your case) and puts
    %# it into the field 'number' in the output structure, and it looks for the date
    %# and puts it into the field 'date' in the output structure
    %# Specifically, \d finds digits, \d+ finds one or several digits, _\d+_
    %# finds one or several digits that are preceded and followed by an underscore
    %# _(?<number>\d+)_ finds one or several digits that are preceded and follewed 
    %# by an underscore and puts them (as a string) into the field 'number' in the 
    %# output structure. The date part is similar, except that regexp looks for 
    %# specific numbers of digits
    tmp = regexp(fileNames,'_(?<number>\d+)_(?<date>\d{4}_\d{2}_\d{2})','names');
    nameStruct = cat(1,tmp{:}); %# regexp returns a cell array. Catenate for ease of use
    
    %# maybe you want to loop, or maybe not (it's not quite clear from the question), but 
    %# here's how you'd do with a loop. Anyway, since the information about the filenames
    %# is conveniently stored in nameStruct, you can access it any way you want.
    for iFile =1:nFiles
       %# do some processing, get the matrix M
    
       %# and create the output file name
       outputFileX = sprintf('newfileX_%s_%s.xls',nameStruct(iFile).number,nameStruct(iFile).date);
       %# and save
       xlswrite(outputFileX,M)
    end
    

    See regular expressions for more details on how to use them. Also, you may be interested in
    uipickfiles to replace uigetfile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a C# program to read an Excel .xls/.xlsx file and output to
My code was quite sufficient for reading xls file in C# (using Microsoft.Jet.Oledb.4.0) but
Reading through this question on multi-threaded javascript, I was wondering if there would be
Reading this post has left me wondering; are nightly builds ever better for a
currently I am having sucsess with reading the excel file with my c# ,net
I've got a problem using pyExcelerator when reading some xls-files. There're some python scripts
I'm reading an Excel file with OLDB Connection using this code var connectionString =
I am reading excel file and for that I do have connection string in
I am reading an Excel file using good old OleDBConnections and OleDBCommands. How do
Reading this question I found this as (note the quotation marks) code to solve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.