Subtracting values form rows with same variable
이전 댓글 표시
I need to subtract the "mean_Testvalue" from "GENE" A from every other GENE (B,C,D,...) that has the same "TIME" string.
So for example GENE B "diff1 day60" needs to be substracted by the value of GENE A "diff1 day60".

How can i automate this process?
Thank you in advance! :)
채택된 답변
추가 답변 (1개)
RAJA SEKHAR BATTU
2022년 10월 27일
편집: RAJA SEKHAR BATTU
2022년 10월 27일
I am not sure about categorical loop
but you can write for loop like below
index1=GENE('A');
index2=GENE('B');
index3=GENE('C');
index4=GENE('D');
x=zeros(index2,1);
y=zeros(index3,1);
z=zeros(index4,1);
for i = 1: length(GENE)
if GENE == 'B'
x(i) = mean_Testvalue(index2) - mean_Testvalue(Index1);
elseif GENE == 'C'
y(i) = mean_Testvalue(index3) - mean_Testvalue(Index1);
elseif GENE == 'D'
z(i) = mean_Testvalue(index4) - mean_Testvalue(Index1);
end
end
댓글 수: 3
Rik
2022년 10월 27일
Did you mean to write ==? Your other code also doesn't make much sense to me. Are you expecting an output similar to ismember?
RAJA SEKHAR BATTU
2022년 10월 27일
Yes,
I mean to save the substracted values in variables
these variables can be used to manipulate in rows or coloumns
The variable or function GENE does not depend on your loop variable, so each iteration will execute the same branch. You should also avoid using == for text comparisons, as that may result in unexpected results:
if 't'=='tt'
disp('did you expect this outcome?')
else
disp('or this one?')
end
카테고리
도움말 센터 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!