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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:45:48+00:00 2026-05-25T16:45:48+00:00

I am trying to read a text file which contains the data for several

  • 0

I am trying to read a text file which contains the data for several matrices and load them in different matrices in matlab. An example of my text file looks like this:

19.623 -15.67 42.995
17.942 -10.923 47.112
23.806 -14.332 49.912
21.582 -11.218 46.203
18.031 -12.567 44.381
15.931 -18.897 39.046
18.497 -17.457 44.327

17.548 -18.604 44.24
15.931 -18.897 39.046
18.43 -16.582 43.091
18.497 -17.457 44.327
16.695 -17.627 39.364
17.548 -18.604 44.24

20.436 -16.416 44.281
17.984 -16.918 44.441
14.703 -17.17 40.697
17.078 -18.111 44.22
16.322 -16.342 38.961
19.582 -18.281 39.937
14.941 -16.27 39.53
18.43 -16.582 43.091

This file represents three matrices where the first, second and third matrices dimensions are 7×3, 6×3 and 8×3 respectively. The matrices are separated using a new line. I have tried using S = LOAD(FILENAME) command but this command creates a 21×3 matrices which is concatenation of all the rows. How can I define a matrix separator (delimiter) for my matrices so it produces different matrices based on different segment of my file? Note that the number of all columns is always 3.

Thanks a million for all your help. I really appreciate it.

  • 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-25T16:45:48+00:00Added an answer on May 25, 2026 at 4:45 pm

    If you do not have NaN values in your data, you can use textscan with a \n delimiter. It produces NaN values when a blank line is read. Not very elegant but it does the trick. I am sure there are plenty of other ways of doing this.

    fid=fopen('data','r');
    data=textscan(fid,'%f','delimiter','\n');
    fclose(fid);
    data=cell2mat(data);
    index=find(isnan(data));
    A=data(1:index(1)-1);
    B=data(index(1)+1:index(2)-1);
    C=data(index(2)+1:end);
    A=reshape(A,[3 length(A)/3])';
    B=reshape(B,[3 length(B)/3])';
    C=reshape(C,[3 length(C)/3])';
    

    I must add that if you have any control over how these data files are created you should probably think of changing their format to either one matrix per file or a Matlab mat file.

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

Sidebar

Related Questions

Here I'm trying to read a text file which contains only integers.in every line.For
I am trying to read in a text input file that contains a list
I am trying to read the contents of a file (which contains both 'standard'
I am trying to read a text file which is set in CLASSPATH system
I need to read the string in the text file which contains the default
I am trying to read a text file into matlab where the text file
I'm trying to read the contents of a text file, in this case a
I am trying to read some info from a text file by using windows
I'm trying to read a list of items from a text file and format
I'm trying to read the contents of a small text file using the common

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.