matlab - Apply the same function multiple time with different sets of arguments -
here part of function, want past 4 sets of data function blood_type.
in each set, 1 of arguments numeric , character.
for output type , vol, each of them 3d-matrix of size 80*80*2.
i want have neat way such can obtain all_type result concatenating 4 outputs of blood_type (each type each patient_id , patient_name).
all_type = cat(3, type1, type2, type3, type4)
similarly, want have
all_vol = cat(3, vol1, vol2, vol3, vol4)
instead of writing:
[type1 vol1] = blood_type(1, 'ann'); [type2 vol2] = blood_type(2, 'ben'); [type3 vol3] = blood_type(3, 'chris'); [type4 vol4] = blood_type(4, 'david'); are there ways can choose pair of arguments , produce outputs more efficient? because have hundreds of patients , cumbersome if type hundreds of times names , ids.
thanks in advance.
here's approach, using cellfun;
%'the arguments of function need 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{:}); 
Comments
Post a Comment