Code covered by the BSD License  

Highlights from
isblank.m

2.0

2.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 1.15 KB File ID: #28659

isblank.m

by janez

 

08 Sep 2010 (Updated 09 Sep 2010)

Determines if the argument string consists only of blanks.

| Watch this File

File Information
Description

Function determines whether the string str consists only of blank characters. For strings of blank characters function returns logical 1. For empty strings function returns logical 0. For non-character arguments function returns a type mismatch error.

Examples:
>> isblank(' ')
ans =
1
>> isblank(' foo ')
ans =
0

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
08 Sep 2010 Oleg Komarov

Help and H1 line may be improved. No examples. No history.

Fails if matrix char:
x = [' '
      ' '];

Also I would rather go for all(isspace(x))) even though my timings indicate that isblank can be ?faster?

The main engine can be simplified:
x = all(x==blanks(length(x)));

Oleg

09 Sep 2010 janez

thanks for your comments oleg. they were very useful and also my timings indicate all(isspace(x)) solution is most of the time 1.5-2 times faster than isblank and the x = all(x==blanks(length(x))) solution is about 20% faster.

i also noticed my complicated code is sometimes faster - how is that possible indeed? but good point there too: speedwise my code is the worst most of the time.

i'm sure it's clear from this which solution to use ;) but i'll keep my file posted anyway for pedagogical purposes - i don't want to extinguish your comment.

09 Sep 2010 Jan Simon

You can omit the call of BLANKS:
  x = all(x==blanks(length(x)));
Faster (does not overwrite x, considers matrices):
  y = all(x(:)==' ');
But ISSPACE catchs other invisible characters also:
  y = all(x(:) <= ' '); % or <= 32
Because all characters with ASCII < 33 are invisible.

09 Sep 2010 Binbin Qi

I think the main engine can be simplified:
                    x=length(deblank(x))==0

09 Sep 2010 Binbin Qi

also, all(x==' ')
           all(isspace(x))

Please login to add a comment or rating.
Updates
09 Sep 2010

added two examples of use.

Tag Activity for this File
Tag Applied By Date/Time
blanks janez 08 Sep 2010 09:13:42
data import janez 08 Sep 2010 09:13:42
data export janez 08 Sep 2010 09:13:42
measurement janez 08 Sep 2010 09:13:42

Contact us at files@mathworks.com