필터 지우기
필터 지우기

Plotting data against a combination array

조회 수: 3 (최근 30일)
Raymond Elliott
Raymond Elliott 2023년 10월 26일
댓글: Raymond Elliott 2023년 10월 27일
I have created a combination array of two vectors ranging from -60 to +60 with increments of 1. I am assigning the first column of the combination matrix to X and the second column to Y. I am then looping through every combination of this array, and using the X and Y values to output my Z value, so for every unique combination of X and Y, I have a unique value for Z. I have tried doing a 3D plot, but am running into issues with the X and Y parameters because they are not linear. Any help is greatly appreciated!
alpha = 0;
L = 0.002;
W = 0.002;
x = 0;
y = 0;
h = 0.001;
thetaX_loop = -60:1:60;
thetaY_loop = -60:1:60;
combo = table2array(combinations(thetaX_loop,thetaY_loop));
Z = zeros(length(combo),4);
for i = 1:length(combo)
X = combo(i,1);
Y = combo(i,2);
deltaX = tand(thetaX)*cosd(alpha)*h;
deltaY = tand(thetaY)*cosd(alpha)*h;
A1 = (W-x-deltaX)*(L-y-deltaY);
A2 = (W+x+deltaX)*(L-y-deltaY);
A3 = (W-x-deltaX)*(L+y+deltaY);
A4 = (W+x+deltaX)*(L+y+deltaY);
Em = cosd(thetaX)*cosd(thetaY);
Z1 = A1*Em;
Z2 = A2*Em;
Z3 = A3*Em;
Z4 = A4*Em;
Z_tot = [Z1,Z2,Z3,Z4];
Z(i,:) = Z_tot;
end

채택된 답변

Walter Roberson
Walter Roberson 2023년 10월 26일
alpha = 0;
L = 0.002;
W = 0.002;
x = 0;
y = 0;
h = 0.001;
thetaX_loop = -60:1:60;
thetaY_loop = -60:1:60;
[thetaX, thetaY] = ndgrid(thetaX_loop,thetaY_loop);
deltaX = tand(thetaX).*cosd(alpha)*h;
deltaY = tand(thetaY).*cosd(alpha)*h;
A1 = (W-x-deltaX).*(L-y-deltaY);
A2 = (W+x+deltaX).*(L-y-deltaY);
A3 = (W-x-deltaX).*(L+y+deltaY);
A4 = -(W+x+deltaX).*(L+y+deltaY);
Em = cosd(thetaX).*cosd(thetaY);
Z1 = A1.*Em;
Z2 = A2.*Em;
Z3 = A3.*Em;
Z4 = A4.*Em;
tiledlayout('flow');
nexttile(); surf(thetaX, thetaY, Z1, 'edgecolor', 'none'); colorbar(); title('Z1'); xlabel('{\theta}X'); ylabel('{\theta}Y');
nexttile(); surf(thetaX, thetaY, Z2, 'edgecolor', 'none'); colorbar(); title('Z2'); xlabel('{\theta}X'); ylabel('{\theta}Y');
nexttile(); surf(thetaX, thetaY, Z3, 'edgecolor', 'none'); colorbar(); title('Z3'); xlabel('{\theta}X'); ylabel('{\theta}Y');
nexttile(); surf(thetaX, thetaY, Z4, 'edgecolor', 'none'); colorbar(); title('Z4'); xlabel('{\theta}X'); ylabel('{\theta}Y');
  댓글 수: 1
Raymond Elliott
Raymond Elliott 2023년 10월 27일
Thank you so much this is exactly what I was looking for! :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by