Path: news.mathworks.com!newsfeed-00.mathworks.com!solaris.cc.vt.edu!news.vt.edu!news.glorb.com!postnews.google.com!a32g2000yqm.googlegroups.com!not-for-mail
From: ImageAnalyst <imageanalyst@mailinator.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: EVAL within EVAL
Date: Sun, 1 Nov 2009 19:43:29 -0800 (PST)
Organization: http://groups.google.com
Lines: 23
Message-ID: <90581289-37e3-4d12-aeb6-30b8c88289ea@a32g2000yqm.googlegroups.com>
References: <hclda3$slq$1@fred.mathworks.com> <f94955c1-38ae-48ba-a617-984604e29e1a@j11g2000vbi.googlegroups.com> 
	<c18aae70-b609-444f-9afa-cb27576d39f9@l13g2000yqb.googlegroups.com> 
	<hcljva$e6j$1@fred.mathworks.com>
NNTP-Posting-Host: 75.186.70.56
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1257133409 3277 127.0.0.1 (2 Nov 2009 03:43:29 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 2 Nov 2009 03:43:29 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: a32g2000yqm.googlegroups.com; posting-host=75.186.70.56; 
	posting-account=0rLUzAkAAABojYSRC64DkTbtiSCX77HH
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; 
	GTB6; CyberSafe-IWA-Enable; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 
	3.0.04506.648; .NET CLR 3.5.21022; AskTB5.5),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:581720


Then how about this?  You can probably adapt this to your real needs:

clc;
close all;
clear all;
workspace; % Show the Workspace panel.
% Make up some random names that DO exist.
N1 = ones(1,10);
N20 = rand(1, 15);
N42 = ones(1,10);
N69 = rand(1, 16);
% The other ones don't exist.
for k = 1:500 % to the biggest you ever expect to have.
	varName = sprintf('N%d', k);
	if exist(varName, 'var')
		fprintf(1, '%s exists!\n', varName);
		commandLine = sprintf('%s(~any(%s,2),:) = [];', varName, varName);
		eval(commandLine);
		eval(varName); % Display new values in command window.
	else
		fprintf(1, '%s does not exist.\n', varName);
	end
end