필터 지우기
필터 지우기

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일)
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