Clear Filters
Clear Filters

Plotting data against a combination array

3 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 26 Oct 2023
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');

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!