Path: news.mathworks.com!not-for-mail
From: "Ariel Krieger" <srigi001@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: EVAL within EVAL
Date: Mon, 2 Nov 2009 01:40:19 +0000 (UTC)
Organization: New York University
Lines: 31
Message-ID: <hclda3$slq$1@fred.mathworks.com>
Reply-To: "Ariel Krieger" <srigi001@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257126019 29370 172.30.248.35 (2 Nov 2009 01:40:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 2 Nov 2009 01:40:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1889337
Xref: news.mathworks.com comp.soft-sys.matlab:581710


Hello all,

I'm trying to do something very basic with EVAL but not getting there.

So I have a set of vectors x1...xn and in a for loop I want to perform some arithmatic on them.

I use EVAL to create them automatically with the proper name and all:

for i = 1:10
eval(['x' num2str(i) ' = ones(1,100)']);
end

that creates vectors x1, x2, ..., x10 which are 1 X 100 row vectors containing ones.

Now the problem is I want to do something like this (just for example):

x1 = x1 * 3;
x2 = x2 * 3;
.
.
.

can I use eval within eval? I'm trying something like:

for i = 1: 10
eval(['x' num2str(i) ' = eval(['x' num2str(i) ' ']) * 3']);
end

but obviously that doesn't fly, any suggestions?

Thanks