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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:09:58+00:00 2026-05-27T20:09:58+00:00

Consider the following text(csv) file: 1, Some text 2, More text 3, Text with

  • 0

Consider the following text(csv) file:

1, Some text
2, More text
3, Text with comma, more text

How to load the data into a 2D array in Octave? The number can go into the first column, and all text to the right of the first comma (including other commas) goes into the second text column.

If necessary, I can replace the first comma with a different delimiter character.

  • 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-27T20:09:58+00:00Added an answer on May 27, 2026 at 8:09 pm

    After many long hours of searching and debugging, here’s how I got it to work on Octave 3.2.4. Using | as the delimiter (instead of comma).

    The data file now looks like:

    1|Some text
    2|More text
    3|Text with comma, more text
    

    Here’s how to call it: data = load_data('data/data_file.csv', NUMBER_OF_LINES);

    Limitation: You need to know how many lines you want to get. If you want to get all, then you will need to write a function to count the number of lines in the file in order to initialize the cell_array. It’s all very clunky and primitive. So much for “high level languages like Octave”.

    Note: After the unpleasant exercise of getting this to work, it seems that Octave is not very useful unless you enjoy wasting your time writing code to do the simplest things. Better choices seems to be R, Python, or C#/Java with a Machine Learning or Matrix library.

    function all_messages = load_data(filename, NUMBER_OF_LINES)
      fid = fopen(filename, "r");
    
      all_messages = cell (NUMBER_OF_LINES, 2 );
      counter = 1;
    
      line = fgetl(fid);
    
      while line != -1
          separator_index = index(line, '|');
          all_messages {counter, 1} = substr(line, 1, separator_index - 1); % Up to the separator
          all_messages {counter, 2} = substr(line, separator_index + 1, length(line) - separator_index); % After the separator
          counter++;
    
          line = fgetl(fid);
      endwhile
    
      fprintf("Processed %i lines.\n", counter -1);
      fclose(fid);
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following HTML: <td> Some Text <table>.....</table> </td> I need to manipulate
Consider the following document <html> <body> This is some content <script type=text/javascript src=verySlowToRespond.js></script> This
Let's consider following html code: <p> Some text followed by <span>a span element</span> and
I want to parse text from a xml file.Consider that I have a some
Consider the following example : HTML: <div class=wrapper> <div class=left>Some text here</div><div class=right>Hello Stack
Consider following text file: something something something = someother thing other thing = third
Consider following code : <p style=margin: 30px 0; padding: 0;>Some text some text some
Consider the following code for printing questions from text file: foreach ($lines as $line_num
Consider I have the following text in a UILabel (a long line of dynamic
Consider the following code in VB9: Dim text = Line1<br/>Line2 Dim markup = <span><%=

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.