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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:34:07+00:00 2026-06-10T05:34:07+00:00

I have a file with a list of records which I parse one line

  • 0

I have a file with a list of records which I parse one line at a time. Each record is newline delimited and each value is space delimited. This is just a simplified example, but it has a similar structure to the real data.

Bob blue pizza
Sally red sushi

The first value is a name, then their favorite color, then their favorite food. Let’s say this is in a processing loop and I want to set variables up for each value. For the first line, my values should look like this.

friendsName = "Bob";
favoriteColor = "blue";
favoriteFood = "pizza";

I read in the line and start out with

lineInFile = "Bob blue pizza";

strsplit seems like a good idea, but it outputs a cell array instead of a matrix of strings and I end up with

strsplit(lineInFile, " ") =
{
  [1,1] = Bob
  [1,2] = blue
  [1,3] = pizza
}

I want something like

{friendsName,favoriteColor,favoriteFood} = strsplit(lineInFile, " ");

This gives me error: invalid lvalue function called in expression

Arrays can be used as lvalues, so I tried

cell2mat(strsplit(lineInFile, " "))
ans = Bobbluepizza

That’s not what I want.

  • 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-10T05:34:08+00:00Added an answer on June 10, 2026 at 5:34 am

    This worked.

     [friendsName favoriteColor favoriteFood] = strsplit(lineInFile, " "){1,:}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data file in which each line represents a single record and
Does File.list() have a longer run time if there are more files in its
I have a php file which has one form and 2 submit buttons, onclick
I have an incoming XML file with a list structure: <list> <listItem> <name>elementOne</name> <value>elementOneValue</name>
I have a php file list.php <?php $arr=array('444','555'); echo var_export($arr); ?> Now I want
I have a file containing a list of filenames: esocket.c esocket.h dockwin.cpp dockwin.h makefile
I have a file that contain list of numbers that looks like this: 10^-92
I have long file with the following list: /drivers/isdn/hardware/eicon/message.c//add_b1() /drivers/media/video/saa7134/saa7134-dvb.c//dvb_init() /sound/pci/ac97/ac97_codec.c//snd_ac97_mixer_build() /drivers/s390/char/tape_34xx.c//tape_34xx_unit_check() (PROBLEM)/drivers/video/sis/init301.c//SiS_GetCRT2Data301() /drivers/scsi/sg.c//sg_ioctl()
I have a file that essentially a list of XPaths like so: /Options/File[1]/Settings[1]/Type[1] /Options/File[1]/Settings[1]/Path[1]
I have a list of keywords in a keywords.txt file. I have another file

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.