필터 지우기
필터 지우기

for loop inside a if else loop

조회 수: 1 (최근 30일)
Akshay Pratap Singh
Akshay Pratap Singh 2019년 12월 5일
댓글: Akshay Pratap Singh 2019년 12월 9일
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')

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 12월 5일
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
  댓글 수: 1
Akshay Pratap Singh
Akshay Pratap Singh 2019년 12월 9일
thank you, the problem has now been solved.

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by