for loop inside a if else loop

I am trying to write a code for multivariable fuction. I want all values of p2 and want to extract unique values.
The code is as follow
clear all
clc
format longEng
syms z y1
phi=(pi/180)*39;
delta=(pi/180)*26;
gma=18.4;
beta=2
h=2;
h1=2;
L=h+h1;
kh=0.0;
kv=0;
R2=3*(beta*(1-y1))^0.5
psi=atan(kh/(1-kv));
delm23=0.5*(3-1)*delta;
k23=1+0.5*(3-1)*((cos(phi-psi)^2/(cos(psi)*(cos(delm23+psi)*...
(-sqrt((sin(phi+delm23)*sin(phi-psi))/(cos(delm23+psi)))+1)^2)))-1)
delm213=0.5*(R2-1)*delta
k213=1+0.5*(R2-1)*((cos(phi-psi)^2/(cos(psi)*(cos(delm213+psi)*...
(-sqrt((sin(phi+delm213)*sin(phi-psi))/(cos(delm213+psi)))+1)^2)))-1)
delm201=0.5*(1-R2)*delta;
k201=(2*cos(phi-psi)^2)/(cos(phi-psi)^2*(1+R2)+cos(psi)*cos(delm201+psi)...
*(1-R2)*(1+sqrt((sin(phi+delm201)*sin(phi-psi))/cos(delm201+psi)))^2)
i=0;
for z=0:0.1:L
i=i+1;
if(z<=h)
p1(i)=0.2*z;
p2(i)=0;
else
p1(i)=0.5*z;
j=0;
for y1=0:0.1:1
j=j+1
if (y1>=0 && y1<=(1-(1/beta)))
p2(i,j)=-gma*(z-h)*k23*cos(delm23)
elseif (y1>(1-(1/beta)) && y1<=(1-(1/(9*beta))))
p2(i,j)=-gma*(z-h)*eval(subs(k213*cos(delm213)))
else
p2(i,j)=-gma*(z-h)*eval(subs(k201*cos(delm201)))
end
end
end
end
z=0:0.1:L;
% subplot(2,1,1);
plot(p1,z,p2,z)
grid on
set(gca, 'YDir','reverse')

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Déc 2019

0 votes

In each iteration code store the p2(i, j) element. After the loop execute, you may use unique function, ??
result=unique(p2); %retun an 1D array with unique elements

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by