Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to add the value of elements that have a value that is more than a certain boundary value in the vector automatically?

1 回表示 (過去 30 日間)
Eddy Iswardi
Eddy Iswardi 2020 年 3 月 28 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I don't know how to add value of my vector automatically. However I have two cluster for 'y' vector. That are the element of y less than 10 and the elements of y more than 10. This is the cluster code
yrendah=sum(y(:) <= 10);
ytinggi=sum(y(:) > 10);
In my algorithm, after I find the value of 'sx', I will update the value of 'y'. Where each element of 'y' which has a value of more than 10 will be added to the value of 'sx'. And for the element 'y' which has a value of less than 10 does not change. How do I add up each 'y' element that has a value of more than 10 with 'sx'?. This is my full code
clc;
clear all;
T=readtable('EVASUSANTIDATA.xlsx');
x1=T.PENDAFTARAN;
x2=T.TUNDA;
x3=T.KUOTA;
y=T.LAMA;
yn=length(y);
yrendah=sum(y(:) <= 10);
ytinggi=sum(y(:) > 10);
for i=1:yn
if y(i)<=10
c=x3(i);
while y(i)<=10
c=c-1;
y(i)=(x1(i)+x2(i))/(c);
end
if y(i)>=10
y(i)=(x1(i)+x2(i))/(c+1);
end
d=c+1;
k(i)=x3(i)-d;
end
end
sx=round(sum(k)/ytinggi);
sxx=rem(sum(k),ytinggi);
  3 件のコメント
Eddy Iswardi
Eddy Iswardi 2020 年 3 月 28 日
Do you know how to add automatically 'sx' to the 8 elements with the highest value?

回答 (1 件)

David Hill
David Hill 2020 年 3 月 28 日
y(ismember(y,maxk(y,8)))=y(ismember(y,maxk(y,8)))+sx;

製品

Community Treasure Hunt

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

Start Hunting!

Translated by