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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:06:06+00:00 2026-06-14T22:06:06+00:00

I want to sum files which I created with fprintf . I have 5

  • 0

I want to sum files which I created with fprintf. I have 5 text files that contain something like this (1 column 8 rows):

0.1811  
0.0889  
-0.1073  
-0.0777  
-0.0596  
0.0971  
0.1021  
0.3730  

I’m trying to load those files into workspace and sum those columns. I could sum columns of two files, but with the last 3 files sums works only for last rows (row number 8). I understand it has something to do with loading and opening files. The last two files were loaded with:

SumFid=fopen(MyFile,'a');   %this is how my 2 files work opened
FID=fopen(FirstFile);  
MatrixSub = load(FirstFile);  
m = textscan(FID,'%f %f %f %f %f %f %f');  
horzcat(m{:})      

While for the other 3 files I’m using:

Wfid=fopen(VFile,'a');  
Mat = load(VFile);  
VData = fscanf(Wfid,'%f',[8,1]);  

When I try to use same texscan and horzcat as with the previous two it gives error out of memory, but with the latter code it only sums last rows of those file contents when I try:

for i = i:8  
  Sum = A+B % this from first 2 files works  
  Sum3Files = file1+file2+files3;        
end  

I know it looks probably pretty trivial but I’m new in MATLAB and would appreciate your help much.

  • 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-14T22:06:07+00:00Added an answer on June 14, 2026 at 10:06 pm

    I think something like this is what you’re after:

    total = 0;
    files = {'data.txt' 'data2.txt'};  % add more files here
    
    for ii = 1:numel(files)
    
        fid = fopen(files{ii});
            C = textscan(fid, '');        
        fclose(fid);
    
        total = total + [C{:}];
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a text file that looks like this (including the filename matches
Crazy question...however, I want the sum of all the rows in a table for
I want to display sum of a column in a textbox when I hit
I want to use Expression.Add to sum two data types, which might be a
I want to create a method sum that I can call on different types,
I have a directory with XML files. I quickly want to go through them
Hi I have a file like this: probeset_id submitted_id chr snp_pos alleleA alleleB 562_201
I have a sample file like this: probeset_id submitted_id chr snp_pos alleleA alleleB 562_201
Ok here is my problem. I have a csv file that is created out
I want to calculate the total size of all .mobi files from this link

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.