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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:24:27+00:00 2026-06-10T02:24:27+00:00

I have a cell array 3×1 like this: name1 = text1 name2 = text2

  • 0

I have a cell array 3×1 like this:

name1 = text1
name2 = text2
name3 = text3

and I want to parse it into separate cells 1×2, for example name1 , text1. In future I want to treat text1 as a string to compare with other strings. How can I do it? I am trying with regexp and tokens, but I cannot write a proper formula for that, if someone can help me with it please, I will be grateful!

  • 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-10T02:24:29+00:00Added an answer on June 10, 2026 at 2:24 am

    This code

    input = {'name1 = text1';
             'name2 = text2';
             'name3 = text3'};
    
    result = cell(size(input, 1), 2);
    for row = 1 : size(input, 1)
        tokens = regexp(input{row}, '(.*)=(.*)', 'tokens');
        if ~isempty(tokens)
            result(row, :) = tokens{1};
        end
    end
    

    produces the outcome

    result = 
        'name1 '    ' text1'
        'name2 '    ' text2'
        'name3 '    ' text3'
    

    Note that the whitespace around the equal sign is preserved. You can modify this behaviour by adjusting the regular expression, e.g. also try '([^\s]+) *= *([^\s]+)' giving

    result = 
        'name1'    'text1'
        'name2'    'text2'
        'name3'    'text3'
    

    Edit: Based on the comments by user1578163.

    Matlab also supports less-greedy quantifiers. For example, the regexp '(.*?) *= *(.*)' (note the question mark after the asterisk) works, if the text contains spaces. It will transform

    input = {'my name1 = any text1';
             'your name2 = more text2';
             'her name3 = another text3'};
    

    into

    result = 
        'my name1'      'any text1'    
        'your name2'    'more text2'   
        'her name3'     'another text3'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in MATLAB I have a cell array like this a = { 1 2
I have created a cell array of structure-files, like this for example: >> res2
I have a list (cell array) of elements with structs like this: mystruct =
I have a cell array of anonymous function handles, and would like to create
I have a cell array like a={'potential'; 'impact'; 'of'; 'stranded'; 'assets'; 'and'; 'other'; 'necessary';
I have this cell array in MATLAB: y = { 'd' 'f' 'a' 'g'
So, I have a cell-array of 1xN vectors of different lengths. I want to
I have a vector of temperatures and a cell array of Date/Time. I want
I have this cell array: date_hour = '30/07/2012 00:00' '30/07/2012 01:00' '30/07/2012 02:00' '30/07/2012
I have a 2D cell array. I want to do the following: y =

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.