使用不同的参数集多次应用相同的函数

时间:2015-08-05 11:44:28

标签: matlab function cell

以下是我的功能的一部分,我希望将4组数据传递到我的函数blood_type

在每个集合中,其中一个参数为numeric,另一个参数为character

对于输出TypeVol,每个输出都是大小为80*80*2的3D矩阵。

enter image description here

我希望有一个简洁的方法,以便我可以获得ALL_TYPE,这是通过连接blood_type的4个输出(每个类型来自每个patient_id和{{1}的结果}})。

patient_name

同样,我想要

ALL_TYPE = cat(3, Type1, Type2, Type3, Type4)

而不是写作:

ALL_VOL = cat(3, Vol1, Vol2, Vol3, Vol4)

有没有什么方法可以选择这对参数并使输出更有效?这是因为我有数百名患者,如果我输入数百次姓名及其ID,这将很麻烦。

提前致谢。

1 个答案:

答案 0 :(得分:2)

这是一种方法,使用cellfun;

%'The arguments of the function need to be typed once anyways'
patient_id   = {1,2,3,4};
patient_name = {'Ann','Ben','Chris','David'};

[ALL_TYPE, ALL_VOL] = cellfun( ...
   @blood_type, patient_id, patient_name, ...
   'UniformOutput', false ...
);

ALL_TYPE = cat(3, ALL_TYPE{:});
ALL_VOL  = cat(3, ALL_VOL{:});