- The code provided uses both the index value "l" and the value of the vector "a" at index "l" in the inner for loops. However, you will only be passing the values "[aValue, WValue]" when using meshgrid and an anonymous function.
- Anonymous functions cannot contain explicit “for” loops and “if” clause statements.
Parameter sweep with meshgrid using a function containing a for loop
5 views (last 30 days)
I am calculating the time evolution of the following system using a for loop as in the code below.
trainLen = 30;
initLen = 3;
data = [1:1:trainLen]; %%Some data
inSize = 1;
resSize = 50;
Win = (rand(resSize,1+inSize)-0.5) .* 1;
W = rand(resSize,resSize)-0.5;
a = 0.95;
X = zeros(1+inSize+resSize,trainLen-initLen);
x = rand(resSize,trainLen);
for t = 1:trainLen
u = data(t);
x(:,t+1) = (1-a)*x(:,t) + a*tanh( Win*[1;u] + W*x(:,t) );
if t > initLen
X(:,t-initLen) = [1;u;x(:,t)];
I would like to perform a parameter sweep over the variables a (a scalar) and W (a matrix) using meshgrid to try and avoid using two for loops, but I am struggling rewriting the (time evolution) for loop as an anonymous function to be used with a and W, as in this example.
Any help would be appreciated.
Ramtej on 17 Aug 2023
I understand that you are trying to avoid using two for-loops to perform parameter sweep using an anonymous function.
You cannot reduce the for loops in your case using “meshgrid” and anonymous functions because of the following two reasons.
Hope this helps!