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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:41:26+00:00 2026-05-14T04:41:26+00:00

Is there is easy command in MATLAB which prevents program from crashing when it

  • 0

Is there is easy command in MATLAB which prevents program from crashing when it reads characters?

I use xlsread to read a (20 400) matrix data , the first row and column get disregarded
as they have headers, so that:

data = xlsread ('C:\file.xls') 

results in data with a size of (19 399).

I have a problem, some cells have missing data and it’s written ‘missing’ and on some data sets i have headers reappear in middle.

Is there a way to skip these characters without the program crashing and me having to open the file in excel and deleting those fields?

Thanks


sorry for the late update. Here is the code i am using:

[a,patha]=uigetfile({'*.csv'},'Select the file' ,'c:\Data\2010'); 
file1=[patha a]; 

%# get a file ID 
fid = fopen(file1,'rt'); 
newf= textscan(fid, ['%s' repmat('%f',1,27)], 'HeaderLines', 1, 'Delimiter', ','); 
fclose(fid) ;

%//Make time a datenum of the first column
time = datenum(newf{1} );

%//Find the difference in minutes from each row
timeDiff = round(diff(datenum(time)*(24*60)));

%//the rest of the data
newf = cell2mat(newf(2:28));

the error i get is:

??? Error using ==> cat
CAT arguments dimensions are not consistent.

Error in ==> cell2mat at 81
            m{n} = cat(2,c{n,:});

Error in ==> testprogram at 31
pwr = cell2mat(newf(2:28));

it is due to the characters in my file i selected. it disappears when i manually delete them

  • 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-14T04:41:26+00:00Added an answer on May 14, 2026 at 4:41 am

    Textscan fails if the string doesn’t match the expectation. The empty entries lead to problems when catenating – your array would have an uneven number of columns.

    textscan('bla,5.4,missing,3,3,3.4','%s%f%f%f%f%f','Delimiter',',')
    
    ans = 
    
        {1x1 cell}    [5.4000]    [0x1 double]    [0x1 double]    [0x1 double]    [0x1 double]
    

    However, you can use’TreatAsEmpty’, to treat ‘missing’ as empty (i.e. they’re replaced by NaNs)

    textscan('bla,5.4,missing,3,3,3.4','%s%f%f%f%f%f','Delimiter',',','TreatAsEmpty','missing')
    
    ans = 
    
        {1x1 cell}    [5.4000]    [NaN]    [3]    [3]    [3.4000]
    

    This allows you to run cell2mat without problems.

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

Sidebar

Related Questions

is there an easy way within TextMate that I can select a string, hit
Is there an easy way of dumping a SQLite database table into a text
Previous I issued a question on how to change Maven project vesion from command
In Git, is there a way to merge all changes from one branch into
Background: writing an automated release script to export changed files between versions from SVN
I've had a search around, and from my perspective using backticks is the only
I'm using Cygwin to start some servers. Each server is launched inside an xterm
I am kind of annoyed by the installation of modules in python and had
I have a library that is meant to be used by many websites. The
I want to do some analysis on some old code and need to be

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.