Dear Matlab coder, How to access multiple row for a single column in a cell. Currently, I had to use this dumb way to access multiple row for the column 8 as shown below. May I know how to further improve the code? The excel file can be download from DataExcel
function [at] = MeanPVT (at) for i = 1:length (at.Valindex) A= (at.Valindex (:,i))'; m1 = (at.raw{A(1),8}); m2 = (at.raw{A(2),8}); m3 = (at.raw{A(3),8}); at.average (i) = (m1+m2+m3)/3; endend
On the same note , is it possible to make the code in the function INDEXINGVALUE more compact. Particularly, is there any way I can remove the usage of SWITCH. In the current framework, the state of the CONDITION_3 is depending to the Condition_TTDay. In other word, CONDITION_3 will have 2 or 3 state if the Condition_TTDay is either BL or (SS1 & SS2).
filename = 'DataExcel.xlsx';[~,~,at.raw] = xlsread(filename,'Sheet1','','basic');at.Condition_Cond = {'ACond' 'BCond'};at.Condition_TTDay = {'BL' 'SS1' 'SS2' 'SS3'};[at] = IndexingValue (at);[at] = MeanPVT (at);function [at] = IndexingValue (at) c= 1; for i=1:2 for j =1:4 at.condition_1 = at.Condition_Cond {i}; at.condition_2 = at.Condition_TTDay {j}; switch at.condition_2 case 'BL' for k =1:2 at.condition_3 = k; at.Valindex (:,c) = calMean (at); c=c+1; end otherwise for k =1:3 at.condition_3 = k; at.Valindex (:,c) = calMean (at); c=c+1; end end end endendfunction Valindex = calMean (at) valid = find(cellfun('isclass', at.raw(:,2), 'char') & ... cellfun('isclass', at.raw(:,3), 'char') & ... cellfun('isclass', at.raw(:,7),'double')); Valindex = ... valid((strcmp(at.raw(valid,2), at.condition_1)) & ... (strcmp(at.raw(valid,3), at.condition_2)) & ... ([at.raw{valid,7}].' == at.condition_3)); end
Best Answer