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

  • Home
  • SEARCH
  • 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 8342937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:54:35+00:00 2026-06-09T05:54:35+00:00

this question about matlab: i’m running a loop and each iteration a new set

  • 0

this question about matlab:
i’m running a loop and each iteration a new set of data is produced, and I want it to be saved in a new file each time. I also overwrite old files by changing the name. Looks like this:

name_each_iter = strrep(some_source,'.string.mat','string_new.(j).mat')

and what I#m struggling here is the iteration so that I obtain files:
…string_new.1.mat
…string_new.2.mat
etc.

I was trying with various combination of () [] {} as well as ‘string_new.’j’.mat’ (which gave syntax error)

How can it be done?

  • 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-06-09T05:54:39+00:00Added an answer on June 9, 2026 at 5:54 am

    For creating a name based of an already existing file, you can use regexp to detect the ‘_new.(number).mat’ and change the string depending on what regexp finds:

    original_filename = 'data.string.mat';
    im = regexp(original_filename,'_new.\d+.mat')
    if isempty(im) % original file, no _new.(j) detected
        newname = [original_filename(1:end-4) '_new.1.mat'];
    else
        num = str2double(original_filename(im(end)+5:end-4));
        newname = sprintf('%s_new.%d.mat',original_filename(1:im(end)-1),num+1);
    end
    

    This does exactly that, and produces:

        data.string_new.1.mat
        data.string_new.2.mat
        data.string_new.3.mat
        ...
    
        data.string_new.9.mat
        data.string_new.10.mat
        data.string_new.11.mat
    

    when iterating the above function, starting with ‘data.string.mat’

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

Sidebar

Related Questions

hopefully this is a basic question about make pattern rules: I want to use
I am relatively new to Matlab and have a question about creating a logical
This is a question about incrementing one value of a MATLAB array multiple times
This question about Timers for windows services got me thinking: Say I have (and
Followed this question about delayed_job and monit Its working on my development machine. But
Note: I originally asked this question about an hour ago but only recently realized
I've this question about pass some instances by ref or not: here is my
I have seen this question about deploying to WebSphere using the WAS ant tasks.
Follow up to this question about GNU make : I've got a directory, flac
This is sort of the Java analogue of this question about C# . Suppose

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.