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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:46:29+00:00 2026-06-13T01:46:29+00:00

I have a huge csv file (as in: more than a few gigs) and

  • 0

I have a huge csv file (as in: more than a few gigs) and would like to read it in Matlab and process each file. Reading the file in its entirety is impossible so I use this code to read in each line:

fileName = 'input.txt';
inputfile = fopen(fileName);

while 1
    tline = fgetl(inputfile);
    if ~ischar(tline)
        break
    end
end
fclose(inputfile); 

This yiels a cell array of size(1,1) with the line as string. What I would like is to convert this cell to a normal array with just the numbers.
For example:

input.csv:
0.0,0.0,3.201,0.192
2.0,3.56,0.0,1.192
0.223,0.13,3.201,4.018

End result in Matlab for the first line:

A = [0.0,0.0,3.201,0.192]

I tried converting tline with double(tline) but this yields completely different results. Also tried using a regex but got stuck there. I got to the point where I split up all values into a different cell in one array. But converting to double with str2double yields only NaNs…

Any tips? Preferably without any loops since it already takes a while to read the entire file.

  • 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-13T01:46:30+00:00Added an answer on June 13, 2026 at 1:46 am

    You are looking for str2num

    >> A = '0.0,0.0,3.201,0.192';
    >> str2num(A)
    ans =
         0  0  3.2010  0.1920
    >> A = '0.0 0.0 3.201 0.192';
    >> str2num(A)
    ans =
         0  0  3.2010  0.1920
    >> A = '0.0     0.0 ,    3.201 , 0.192';
    >> str2num(A)
    ans =
         0  0  3.2010  0.1920
    

    e.g., it’s quite agnostic to input format.

    However, I will not advise this for your use case. For your problem, I’d do

    C = dlmread('input.txt',',', [1 1 1 inf]) % for first line
    C = dlmread('input.txt',',')              % for entire file
    

    or

    [a,b,c,d] = textread('input.txt','%f,%f,%f,%f',1) % for first line
    [a,b,c,d] = textread('input.txt','%f,%f,%f,%f')   % for entire file
    

    if you want all columns in separate variables:

    a = 0
    b = 0
    c = 3.201
    d = 0.192
    

    or

    fid = fopen('input.txt','r');
    C = textscan(fid, '%f %f %f %f', 1); % for first line only
    C = textscan(fid, '%f %f %f %f', N); % for first N lines
    C = textscan(fid, '%f %f %f %f', 1, 'headerlines', N-1); % for Nth line only
    fclose(fid);
    

    all of which are much more easily expandable (things like this, whatever they are, tend to grow bigger over time :). Especially dlmread is much less prone to errors than writing your own clauses is, for empty lines, missing values and other great nuisances very common in most data sets.

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

Sidebar

Related Questions

I have a huge CSV file I would like to process using Hadoop MapReduce
Hello I have a problem wherein I have to read a huge csv file.
I have a huge CSV file with over 700K + lines. I have to
I have to write huge data in text[csv] file. I used BufferedWriter to write
I have a huge checkbox list with different levels and I would like to
I have a UTF-16 CSV file which I have to read. Python csv module
Let's say I have a dictionary of names (a huge CSV file). I want
I have a csv file looks like this col1, col2, col3 1 , John,
I have a 250MB+ huge csv file to upload file format is group_id, application_id,
I have a csv file which is something like this: book_store_id book_price name 1

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.