MATLAB: How to efficiently access multiple value in a cell [ ACCESS MULTIPLE ROW FOR A SINGLE COLUMN]

access cellefficient

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;
end
end
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
end
end
function 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

A first step simplification eliminates superfluous parens and (to my eye, anyway) spaces that make harder to read than without--
for i=1:length(at.Valindex)
A =at.Valindex(:,i).';
m(1)=at.raw{A(1),8};
m(2)=at.raw{A(2),8};
m(3)=at.raw{A(3),8};
at.average(i)=mean(m);
end
which then is seen to be
for i=1:length(at.Valindex)
A =at.Valindex(:,i).';
for j=1:3, m(j)=at.raw{A(j),8}; end
at.average(i)=mean(m);
end
But, addressing by vector for rows for a fixed column is the same result in Matlab--
for i=1:length(at.Valindex)
A =at.Valindex(:,i).';
at.average(i)=mean(at.raw{A(1:3),8});
end
Will be a little more efficient if preallocate at.average to size loop upper limit.
What is at.Valindex, specfically? It may be doable to use arrayfun() or other vector operations and eliminate the loop entirely.
On the other question, I'd venture the answer is probably 'yes' but I'm out of time at the moment; maybe somebody else will take a look there...