Subtracting values form rows with same variable

1 回表示 (過去 30 日間)
Marcel-Maximilian
Marcel-Maximilian 2022 年 10 月 27 日
コメント済み: Marcel-Maximilian 2022 年 11 月 24 日
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! :)
  2 件のコメント
Rik
Rik 2022 年 10 月 27 日
Have you tried a for loop?
Marcel-Maximilian
Marcel-Maximilian 2022 年 10 月 27 日
I thought about that the problem is i am kinda new to MATLAB and don't really know how i would have to design such a loop.

サインインしてコメントする。

採用された回答

Rik
Rik 2022 年 10 月 27 日
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
It sound to me like you need a nested loop. I outlined the idea below.
for row1=1:(size(data,1)-1)
% extract timestamp on this row
for row2=(row1+1):size(data,1)
% extract timestamp on this row
if % test if timestamps match
% apply subtraction and store back to table
end
end
end
  1 件のコメント
Marcel-Maximilian
Marcel-Maximilian 2022 年 11 月 24 日
I am really sorry for the late response. Was quite busy.
Your idea did the trick. Thank you very much. :)

サインインしてコメントする。

その他の回答 (1 件)

RAJA SEKHAR BATTU
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 件のコメント
RAJA SEKHAR BATTU
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
Rik
Rik 2022 年 10 月 27 日
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
did you expect this outcome?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInterpolation of 2-D Selections in 3-D Grids についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by