MATLAB: Create and rotate a vector field out of two matrices (x and y component)

subscripted assignment dimension mismatch

Dear all,
my questions referes to the rotation of a vector field that consists of two matrices (data2_va1 and data2_var2). The dimenson of both matrices is 61×43.
Using a minimal exampe, it works out quite fine.
v=[data2_var1(1,1),data2_var2(1,1)];
theta = 90;
R = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
vR=v*R;
However, trying to use the piece of code to create a vector field v results in the following error message: Subscripted assignment dimension mismatch. Maybe somebody could give me a hint, how to construct a proper vector field out of two matrices (x and y component are seperated in the matrices data2_var1 and data2_var2).
for i=1:size(data2_var1,1)
for j=1:size(data2_var1,2)
v(i,j)=[data2_var1(i,j),data2_var2(i,j)];
end
end
theta = 90; R = [cosd(theta) -sind(theta); sind(theta) cosd(theta)]; v1R(i,j)=v1(i,j)*R;
Thanks a lot in advance, Fernandes

Best Answer

For brevity call X = data2_var1 and Y = data2_var2. Do things this way:
vR=[X(:),Y(:)]*R;
X2 = reshape(vR(:,1),size(X));
Y2 = reshape(vR(:,2),size(Y));
X2 and Y2 constitute the x and y components of your rotated field.