help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Short Cut Way to Assign the Variables x1, x2....x40 names


From: Przemek Klosowski
Subject: Re: Short Cut Way to Assign the Variables x1, x2....x40 names
Date: Mon, 15 Sep 2014 11:08:43 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0

On 09/13/2014 03:12 PM, Nir Krakauer wrote:

for i = 1:40
  eval(['x' num2str(i) ' = y' num2str(i) ' + a;'])
endfor


While true, and it does what the OP literally asked for, it isn't likely to be what he really needs.
My guess is that he is trying to manage 40 data arrays, which in Octave should probably be represented as a 2D array, where the i-th dataset is in the i-th row, y(i,1:end), and his _expression_ then is simply

x=y+a

If the datasets are of different length, a single array won't do and then he needs to use a cell array
where i-th dataset is in cell member y(i), and his _expression_ is

x=cellfun(@(x) x+a,y,"UniformOutput",false)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]