MATLAB: Most efficient way of creating variables

arrayfor looploopMATLABmatrixvariables

I have 8 matrices, (13×10) ,which contain velocites of a flow within a channel (V1,V2…..V8). For each of these I have extarcted the lasts columns using the following :
E1 = V1(:,10);
E2 = V2(:,10);
E3 = V3(:,10);
……
E8 = V8(:,10);
I read the following https://uk.mathworks.com/matlabcentral/answers/57445-faq-how-can-i-create-variables-a1-a2-a10-in-a-loop which mentions that dynamic variable names should be avoided where possible.
In accordance, I attempted to try what the post suggested (Making one matrix with the 8 columns (E):
E = zeros(13,8); % Each column to be replaced by the last columns of V1,V2..V8
for i = [1:8];
E(i) = V(i)(:,10); % Trying to assign final columns of V1,V2..V8 to the columns of E8
end
However, I feel as if this is very far from the correct way of doing this. Any help is appreciated

Best Answer

It's good that you're following that advice.
E = [V1(:,10), V2(:,10), . . ., Vn(:,10)]; % most efficient method of this list
If you want to use a loop, the variables have be to combined before hand,
V = {V1, V2, V3, . . ., Vn};
E = zeros(size(V1,1), numel(v));
for i = 1:numel(V)
E(:,i) = V{i}(:,10);
end
or, if the Vn matrices are all the same size,
V = cat(3, V1, V2, V3, . . ., Vn);
E = squeeze(V(:,10,:));