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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:34:50+00:00 2026-05-13T23:34:50+00:00

I am generating an Excel file through MATLAB and I have empty cells in

  • 0

I am generating an Excel file through MATLAB and I have empty cells in the middle of it. Here is the code I am using to initialize an empty matrix:

newfile = cell(5,5);
[newfile{:}] = deal('');
[newfile{:}] = deal(' ');

I then do some processing and write the data to a file using XLSWRITE. The spreadsheet ends up having some empty cells and some data. Is there a command by which I can delete the empty rows, without effecting the rows which have data in them?

Another question:

Is there a way to append onto this Excel file? I run this file everyday and would like to automatically add data rather than manually copying and pasting everyday.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Addition to above question:

If my output file looks like

1.8 3 -4.7

1.87 3.9 -5.8

1.84 2.8 -4.3

2 3.2 -4.7

2 3.7 -6
2 3.6 -5.2
3 4.3 -6.5

13 4.2 13.1

12 3.5 -6.3

1.65 1.9 -4.4

So how do i delete the empty rows when its not in cell as cellfun does not work for this

  • 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-13T23:34:51+00:00Added an answer on May 13, 2026 at 11:34 pm

    If I understand the first part of your question right, you want to remove any rows in your newfile cell array that contain only empty cells. You can do this using the function CELLFUN to find empty cells, using the function ALL to find the rows that contain all empty cells, and then using logical indexing to remove those rows:

    >> newfile = cell(5,5);  %# Empty cell array
    >> newfile(:) = {''};    %# A different way to assign values without DEAL
    >> newfile([1 2 4 5]) = {'a'}  %# Make some non-empty cells
    
    newfile = 
    
        'a'     ''     ''     ''     ''
        'a'     ''     ''     ''     ''
         ''     ''     ''     ''     ''
        'a'     ''     ''     ''     ''
        'a'     ''     ''     ''     ''
    
    >> emptyIndex = cellfun('isempty',newfile)  %# Logical index of empty cells
    
    emptyIndex =
    
         0     1     1     1     1
         0     1     1     1     1
         1     1     1     1     1
         0     1     1     1     1
         0     1     1     1     1
    
    >> newfile = newfile(~all(emptyIndex,2),:)  %# Removes 3rd row
    
    newfile = 
    
        'a'     ''     ''     ''     ''
        'a'     ''     ''     ''     ''
        'a'     ''     ''     ''     ''
        'a'     ''     ''     ''     ''
    

    EDIT: If you initialize your cell array newfile with blank spaces (' ') instead of empty strings ('') you will have to change the way you compute emptyIndex in the above code. The CELLFUN argument 'isempty' should be changed to @(x) strcmp(x,' ') to get the same results.


    With respect to your second question, you can specify in your call to XLSWRITE the sheet and row/column range in the file where you want to add your data. If you add to the file once per day, the easiest solution may be to add a new sheet with the date as the name. The following writes the data in M to the file fileName, adding a new sheet that is named with the current date and time:

    xlswrite(fileName,M,datestr(now));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do you have any tricks for generating SQL statements, mainly INSERTs, in Excel for
I need to design a small project for generating excel reports in .NET, which
While generating charts using RS 2008 betas, RC0 and such., I never specified any
I'm generating ICalendar (.ics) files. Using the UID and SEQUENCE fields I can update
I'm generating some xml files that needs to conform to an xsd file that
When generating graphs and showing different sets of data it usually a good idea
I'm generating some XML documents and when it comes to the address part I
I'm currently generating an 8-character pseudo-random uppercase string for A .. Z: value =
I'm generating a self-signed SSL certificate to protect my server's admin section, and I
I'm generating a ton of XML that is to be passed to an API

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.