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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:04:52+00:00 2026-05-16T16:04:52+00:00

EDITED QUESTION: I have 2500 rows x 100 columns data in variable named avg_data_models.

  • 0

EDITED QUESTION:

I have 2500 rows x 100 columns data in variable named avg_data_models. I also have 2500 rows x 100 columns variable ‘X’ and similar size matrix variable ‘Y’, both containing the co-ordinates. I want to save the values of this variable in a text (.dat) file which must have 302 header lines in the following manner:

avg_data_models
300
X_1
X_2
.
.
.
X_100
Y_1
Y_2
.
.
.
Y_100
avg_data_models_1
avg_data_models_2
avg_data_models_3
.
.
.
.
.
avg_data_models_100

In the above header style, the first line is the name of the file, the 2nd line tells the number of columns (each column has 2500 rows), and the rest of the 300 lines represent the model of each variable respectively – Like 100 models of X, 100 models of Y and 100 models of avg_data_models.

  • 1 1 Answer
  • 2 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-16T16:04:53+00:00Added an answer on May 16, 2026 at 4:04 pm

    Consider this code:

    %# here you have your data X/Y/..
    %#X = rand(2500,100);
    
    [r c] = size(X);
    prefixX = 'X';
    prefixY = 'Y';
    prefixData = 'avg_data_models';
    
    %# build a cell array that contains all the header lines
    num = strtrim( cellstr(num2str((1:c)','_%d')) );   %#' SO fix
    headers = [ prefixData ;
                num2str(3*c) ;
                strcat(prefixX,num) ;
                strcat(prefixY,num) ;
                strcat(prefixData,num) ];
    
    %# write to file
    fid = fopen('outputFile.dat', 'wt');
    fprintf(fid, '%s\n',headers{:});
    fclose(fid);
    

    EDIT

    It seems I misunderstood the question.. Here’s the code to write the actual data (not the header titles!):

    %# here you have your data X/Y/..
    avg_data_models = rand(2500,100);
    X = rand(2500,100);
    Y = rand(2500,100);
    
    %# create file, and write the title and number of columns
    fid = fopen('outputFile.dat', 'wt');
    fprintf(fid, '%s\n%d\n', 'avg_data_models', 3*size(X,2));
    fclose(fid);
    
    %# append rest of data
    dlmwrite('outputFile.dat', [X Y avg_data_models], '-append', 'delimiter',',')
    

    Note: I used a comma , as delimiter, you can change it to be a space or a tab \t if you like..

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

Sidebar

Related Questions

I edited the question so it would make more sense. I have a function
I have edited the question as what I said before was two pieces of
EDITED QUESTION Hi this is the total workflow of this project we have a
I have edited this question but at the bottom of the program I have
I have edited this question to make it easier to understand. I have an
I have edited this question: At root, I have a working folder F (root/F),
In response to the helpful comments, I have edited the original question (where I
I have edited my question and here is the code which I used for
Original question I have a class named RootViewController and my .h file has the
Question Edited for better understanding: I have a WCF service and any of my

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.