以下是我的功能的一部分,我希望将4组数据传递到我的函数blood_type
。
在每个集合中,其中一个参数为numeric
,另一个参数为character
。
对于输出Type
和Vol
,每个输出都是大小为80*80*2
的3D矩阵。
我希望有一个简洁的方法,以便我可以获得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,这将很麻烦。
提前致谢。
答案 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{:});