I have the following code where I am trying to obtain U for every k value and the values in a cell array:
G = 1×3 cell
If
G{1,1} = [-6.45230249676815e-06; 2.43528862745912e-20; 2.00553181084869e-19; 6.45309629402509e-06; -9.16814514353228e-20; 6.45627245974903e-06]G{1,2} = [-3.22654814674929e-06; -5.38986674121538e-20; -2.25622328702039e-20; 3.22734209049890e-06; -2.25622301386590e-20; 3.23051981960359e-06]G{1,3} = [-2.15129672917826e-06; -2.05328256780239e-20; -6.68510603470547e-21; 2.15209081944770e-06; -6.68510421367576e-21; 2.15527011276720e-06]
and
k = 0.0012k = 0.0025k = 0.0037L1 = 0.1L2= 0.2L3 = 0.4U1 = G(1)*exp(-k*L1)+G(2)*exp(-k*L1);U2 = G(3)*exp(-k*L1)+G(4)*exp(-k*L1);U3 = G(5)*exp(-k*L1)+G(6)*exp(-k*L1);
I need to obtain U1,U2,U3 for each value of k
I have tried using for loops and cellfun() etc.
U1 = cellfun(@(G, k) G(1)*exp(-k*L1)+G(2)*exp(-k*L1), G, k, 'UniformOutput', 0);
but it keeps saying "Error using cellfun Input #3 expected to be a cell array, was double instead."
Can anyone please show me how to perform this in MATLAB?
Best Answer