how to display those value of M, which is only less than 1?

2 Ansichten (letzte 30 Tage)
SAHIL SAHOO
SAHIL SAHOO am 3 Dez. 2022
Kommentiert: Zahrah Walid am 3 Dez. 2022
ti = 0;
tf = 70E-8;
tspan=[ti tf];
KC = 1E-4;
for j = 1:100
y0= [(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1));
(10e-2)*rand(2,1); ((-3.14).*rand(1,1) + (3.14).*rand(1,1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(i.*Y(:,15)) ...
+exp(i.*Y(:,18)) +exp(i.*Y(:,21)) +exp(i.*Y(:,24)) + exp(i.*Y(:,27)) + exp(i.*Y(:,30)) + exp(i.*Y(:,33)) ...
+ exp(i.*Y(:,36)) + exp(i.*Y(:,39)) +exp(i.*Y(:,42)) + exp(i.*Y(:,45)) + exp(i.*Y(:,48)) + exp(i.*Y(:,51)) + exp(i.*Y(:,54))+ exp(i.*Y(:,57)) + exp(i.*Y(:,60))));
M(j) = max(abs(r))
end
% here the 100 values of M will be generate, I want to know how many out of
% 100 have the M value less than 1.000?
function dy = rate_eq(t,y,yita_mn,N,o)
dy = zeros(4*N,1);
dGdt = zeros(N,1);
dAdt = zeros(N,1);
dOdt = zeros(N,1);
P = 2;
a = 1;
T = 2000;
tp = 1E-12;
Gt = y(1:3:3*N-2);
At = y(2:3:3*N-1);
Ot = y(3:3:3*N-0);
k = 1E-4;
for i = 1:N
dGdt(i) = (P - Gt(i) - (1 + 2.*Gt(i)).*((At(i)))^2)./T ;
dAdt(i) = Gt(i)*(At(i));
dOdt(i) = -a.*Gt(i) + o(1,i).*tp;
for j = 1:N
dAdt(i) = dAdt(i) + yita_mn(i,j)*(At(j))*cos(Ot(j)-Ot(i));
dOdt(i) = dOdt(i) + yita_mn(i,j)*((At(j)/At(i)))*sin(Ot(j)-Ot(i));
end
end
dy(1:3:3*N-2) = dGdt;
dy(2:3:3*N-1) = dAdt;
dy(3:3:3*N-0) = dOdt;
n1 = (1:20)';
n2 = circshift(n1,-1);
n61 = n1 +60;
n62 = circshift(n61,-1);
n80 = circshift(n61,1);
j2 = 3*(1:20)-1;
j5 = circshift(j2,-1);
j8 = circshift(j2,-2);
j59 = circshift(j2,1);
dy(n61) = (o(1,n2).' - o(1,n1).').*tp + a.*(Gt(n2) - Gt(n1)) - (k).*(y(j2)./y(j5)).*sin(y(n61)) - (k).*(y( j5)./y(j2)).*sin(y(n61)) + (k).*(y(j8)./y(j5)).*sin(y(n62)) + (k).*(y(j59)./y(j2)).*sin(y(n80));
end

Antworten (1)

Zahrah Walid
Zahrah Walid am 3 Dez. 2022
I'm not sure if you want to replace the values higher than 1 by one specific value or you want to remove them completely; if it is the latter you can add this statment after the for loop:
M=M(int8(M)<1)
Take care that due to Mtlab precision the "0.9999999" can be displayed to you as "1.000" but when you do any logical opertation it deal by its actual value (because this case exists in your code). If you want to print actual values less than 1, you should use this statment instead:
M=M(M<1)
If your purpose was the former, then you can add if condition inside your for loop as follows:
if (max(abs(r))<1)
M(j)=max(abs(r))
else
M(j)=1; %the value you want
end
Care to not use this if condition if you want to remove the values higher than 1 as it will results in NAN elements in your array.
  2 Kommentare
SAHIL SAHOO
SAHIL SAHOO am 3 Dez. 2022
the M value are like this 1.000 0.6453 0.2345 1.000 1.000 1.000 0.2353.............. I want to know only those term which are less than 1.000 for an example, from this set of array i wanted the 0.6453 0.2345 0.2353 only these.
in my program there are 100 value of M I wanted to know how many of them is less than 1.000.
Zahrah Walid
Zahrah Walid am 3 Dez. 2022
Then you should use:
sum(int8(M)<1)
after the for loop.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by