2015-09-26 66 views
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=1; 
h = rate_arr_cst_h(i); 

但我來到這裏仍然是一個單元陣列,這意味着我不能使用小時,評價T = 0.1。

非常感謝您的幫助!

回答

2

使用FOR循環:

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

,或者您可以使用cellfun

hh = cellfun(@(f) f(i), rate_arr_cst_h); 
+0

非常感謝! –

+0

如果任何答案已解決您的問題,請點擊答案旁邊的勾號以接受答案。如果不是,請刪除評論,以便人們知道您需要針對特定​​問題提供進一步幫助。 – scmg

3

當您執行h = rate_arr_cst_h(i);時,您正在訪問單元陣列的i^th元素,該元素仍然是單元格。如果要訪問單元陣列中的i^th單元的內容,則需要執行:h = rate_arr_cst_h{i};。請注意使用大括號。

+0

太謝謝你了! –