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

조회 수: 2 (최근 30일)
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 61x43.
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

채택된 답변

Roger Stafford
Roger Stafford 2013년 6월 22일
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.
  댓글 수: 2
G
G 2013년 6월 22일
Great job. Thank you very much for your straight forward solution.
Roger Stafford
Roger Stafford 2013년 6월 22일
I notice that the way you have set up your rotation matrix R for multiplication on the right, a positive angle would give clockwise rotation and negative, counterclockwise. Is that the way you intend? I am accustomed to the opposite convention.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by