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 7081145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:53:00+00:00 2026-05-28T06:53:00+00:00

Say I have a string in a variable in MATLAB like the following: this

  • 0

Say I have a string in a variable in MATLAB like the following:

this is the first line 
this is the second line 
this is the third line

I would like to add a fixed string at the beginning of each line. For example:

add_substring(input_string, 'add_this. ') 

would output:

add_this. this is the first line 
add_this. this is the second line 
add_this. this is the third line

I know I can do this by looping through the input string, but I am looking for a more compact (hopefully vectorized) way to do this, perhaps using one of MATLAB built-ins such as arrayfun accumarray.

  • 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-28T06:53:01+00:00Added an answer on May 28, 2026 at 6:53 am

    The strcat function is what you’re looking for. It does vectorized concatenation of strings.

    strs = {
        'this is the first line'
        'this is the second line'
        'this is the third line'
        }
    strcat({'add_this. '}, strs)
    

    With strcat, you need to put 'add_this. ' in a cell ({}) to protect it from having its trailing whitespace stripped, which is strcat’s normal behavior for char inputs.

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

Sidebar

Related Questions

Lets say I have a string COLIN. The numeric value of this string would
Say I have defined a variable like this (C++): static const char str[] =
Let's say you have a string like this: char* a=01234 Letting &a=0000, &(a+1)=0001, &(a+2)=0002,
lets say I have a class like this: public class MyClass { private String
I have a String variable abc . Now I would like to check whether
Let's say I have a string like this Hello World, I am xyz, How
let's say I have std::map< std::string, std::string > m_someMap as a private member variable
say I have a string like so Testing How could I have it remove
So say I have a string like so of a path $path = '/path/to/../../up/something.txt';
can anyone help me on this.Lets say I have this array of string e.g.

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.