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

The Archive Base Latest Questions

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

I have 3 txt files with float data. Each file has 17 rows. First

  • 0

I have 3 txt files with float data. Each file has 17 rows. First file has 3 columns,other two have 1 column each. I’m trying concatenate those files into one large file-so that i have 5 columns of those file in one file.
I’d doing this :

alldata = [ ];        
  fid2 = fopen(CombinAttrDiff, 'wt')        
NumberOfFiles = 3        
for K = 1 : NumberOfFiles   %looping over all of the files        
thisfile = sprintf('AttrDiff%d.txt',K)        
thisdata = load(thisfile);        
 alldata = [alldata, thisdata];         
end        
      fprintf(fid2, '%f %f %f %f %f\n',alldata);        
fclose all           

the large output file that is printed out does not concatenate files vertically – all values of first column of 1st file is filling in by rows of the the large output file and then takes second column and conintues filling it in by rows.
what am i doing wrong here? Also is it correct way of concatenating files into one file so that to use it as a matrix later. I want each rows of newly created file to be vector array like this a=[0.32588 0.58425 0.35887 0.00004 0.75544]. I need this so I could compare those rows(arrays) after. I was planning to apply reshape to large file to get matrix after.

I’m newbie in matlab and was trying to make this work a couple of days already.any help wopuld be much apprecited! Thanks!

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

    try

    fprintf( fid2, '%f %f %f %f %f\n', alldata.');
    

    EDIT:
    Why this change works?

    Matlab stores its arrays in memory in a “column stack” fashion: that is, in memory the second element is alldata(2,1). So, when you print alldata to fid2 matlab orders the elements according to their “in memory” order, regardless of the formatting string you gave.
    Transposing the array changes the order to suite what you intend.

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

Sidebar

Related Questions

I have a *.txt files having integers, one on each line. So the file
I have 30 txt files with data And I want to create on the
I have a text file with columns of data and I need to turn
I have a data file comprised of thousands of float values and I want
I have a reasonably large data set (10K files, each with 20K lines). I
I have a text file (c:\input.txt) which has: 2.0 4.0 8.0 16.0 32.0 64.0
I have a .txt file containing data like this: 1,Rent1,Expense,16/02/2010,1,4000,4000 1,Car Loan1,Expense,16/02/2010,2,4500,9000 1,Flat Loan1,Expense,16/02/2010,2,4000,8000
I have a .txt file containing data like this: 0,Rent1,Expense,16/02/2010,1,4000,4000 0,Car Loan1,Expense,16/02/2010,2,4500,9000 0,Flat Loan1,Expense,16/02/2010,2,4000,8000
I have a .txt file which contains a column of unixtime, like (1322485992.420381000), the
I have a file where a data structure containing 6 columns is stored side

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.