2
rate_arr_cst_1 = @(t) 2*sin(t)+10; 
rate_arr_cst_2 = @(t) 3*sin(2*t)+8;
rate_arr_cst_h = {rate_arr_cst_1, rate_arr_cst_2};

I defined a cell array in such way and try to access in the following way:

i=1;
h = rate_arr_cst_h(i);

but what I get here is still a cell array, meaning i can't use h to evaluate t=0.1.

Your help is much appreciated!

scmg
  • 1,904
  • 1
  • 15
  • 24
Loading Zone
  • 177
  • 2
  • 12

2 Answers2

4

When you do h = rate_arr_cst_h(i);, you are accessing the i^th element of the cell array, which is still a cell. If you want to access the contents of i^th cell in the cell array, you need to do: h = rate_arr_cst_h{i};. Note the use of curly brackets.

Autonomous
  • 8,935
  • 1
  • 38
  • 77
2

Either use a for loop:

for ii = 1:numel(rate_arr_cst_h)
    hh(ii) = rate_arr_cst_h{ii}(i);
end

or you can use cellfun:

hh = cellfun(@(f) f(i), rate_arr_cst_h);
scmg
  • 1,904
  • 1
  • 15
  • 24
  • If any of the answers has solved your problem, please kindly accept it by clicking on the tick mark besides the answer. If not, please drop a comment so people knows you need further help on specific problem. – scmg Sep 26 '15 at 18:13