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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:18:51+00:00 2026-05-28T11:18:51+00:00

The following code generates a similar dataset to what I am currently working with:

  • 0

The following code generates a similar dataset to what I am currently working with:

clear all
    a = rand(131400,12);
    DateTime=datestr(datenum('2011-01-01 00:01','yyyy-mm-dd HH:MM'):4/(60*24):...
        datenum('2011-12-31 23:57','yyyy-mm-dd HH:MM'),...
        'yyyy-mm-dd HH:MM');
    DateTime=cellstr(DateTime);
    header={'DateTime','temp1','temp2','temp4','temp7','temp10',...
        'temp13','temp16','temp19','temp22','temp25','temp30','temp35'};

I’m trying to convert the outputs into one variable (called ‘Data’), i.e. have header as the first row (1,:), ‘DateTime’ starting from row 2 (2:end,1) and running through each row, and finally having ‘a’ as the data (2:end,2:end) if that makes sense. So, ‘DateTime’ and ‘header’ are used as the heading for the rows and column respectively. Following this I need to save this into a tab delimited text file.

I hope I’ve been clear in expressing what I’m attempting.

  • 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-28T11:18:52+00:00Added an answer on May 28, 2026 at 11:18 am

    An easy way, but might be not the fastest:

    Data = [header; DateTime, num2cell(a)];
    filename = 'test.txt';
    dlmwrite(filename,1); %# no create text file, not Excel
    xlswrite(filename,Data);
    

    UPDATE:
    It appears that xlswrite actually changes the format of DateTime values even if it writes to a text file. If the format is important here is the better and actually faster way:

    filename = 'test.txt';
    out = [DateTime, num2cell(a)];
    out = out'; %# our cell array will be printed by columns, so we have to transpose
    
    fid = fopen(filename,'wt');
    %# printing header
    fprintf(fid,'%s\t',header{1:end-1});
    fprintf(fid,'%s\n',header{end});
    %# printing the data
    fprintf(fid,['%s\t', repmat('%f\t',1,size(a,2)-1) '%f\n'], out{:});
    fclose(fid);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which generates data similar to mine. The posting here
The following code generates the primaey key for the new record to be inserted
The following code generates warning C4250. My question is, what's the best solution to
The following code generates a FileNotFoundException (using .NET 2.0): using System; using System.Collections.Generic; using
I have the following code (generates a quadratic function given the a, b, and
I don't understand why the following code generates a warning. interface Generic<T> { }
Class 1 has the following code that generates the exception - -(IBAction) searchAllAction: (id)
The following line of code generates the compile time error (PE19) There is no
One of the following pieces of code generates a memory leak, any idea which
I have the following SVG source code that generates a number of boxes with

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.