- #1
MartinV
- 69
- 0
So I have a list of variables, defined in my workspace, and I'm trying to access them each in turn to compare them to a larger matrix A. The eval function calls each variable in turn, stores it under temporary matrix B, then compares it to matrix A, does the necessary calculation, and stores it into matrix Z.
Eval, always the capricious function, works if I try to do it manually but fails as I put this into m file and run it. The warning displayed is 'Undefined function or variable 'AAAN'.' even though that variable is there.
This is my code:
function Z = final(A,list)
B = [];
Z = [];
K = log10(exp(1));
for k = 1:length(list)
eval(strcat('B = ',list{k},';'));
for j = 2:length(B)
for i = 2:length(A)
if A(i,1) == B(j,1) && A(i,2) == B(j,2)
Z = [Z; [A(i,1) A(i,2) K/(A(i,3)-B(1,3))]];
end
end
end
end
end
Now I know most people will advise me to just use cell arrays but since dumping all those matrices into a fresh cell array will take me forever, I'm asking if there is a tweak or two to perform in order to get this to work.
Thanks.
Martin
Eval, always the capricious function, works if I try to do it manually but fails as I put this into m file and run it. The warning displayed is 'Undefined function or variable 'AAAN'.' even though that variable is there.
This is my code:
function Z = final(A,list)
B = [];
Z = [];
K = log10(exp(1));
for k = 1:length(list)
eval(strcat('B = ',list{k},';'));
for j = 2:length(B)
for i = 2:length(A)
if A(i,1) == B(j,1) && A(i,2) == B(j,2)
Z = [Z; [A(i,1) A(i,2) K/(A(i,3)-B(1,3))]];
end
end
end
end
end
Now I know most people will advise me to just use cell arrays but since dumping all those matrices into a fresh cell array will take me forever, I'm asking if there is a tweak or two to perform in order to get this to work.
Thanks.
Martin