How can I extract the logical value in a loop (various columns)?

3 ビュー (過去 30 日間)
DulceEien
DulceEien 2021 年 8 月 27 日
コメント済み: DulceEien 2021 年 9 月 2 日
Hello, I'm runnning my code and my logical value is running, what I would like to do is exctract the logical value for several columns (from column 5 to 10) can I do it in a loop or I have to name various variables and then join them?
idx=logical(idx);
[X,Y]= meshgrid(T2.length,T.length);
C = X(idx);
D = Y(idx);
delta = (C - D);
t = table(D,C,delta);
T2 and T are the table were I'm talking the values lenght is in the 5th column and I would like to do the same for column 6,7,8,9,10 is it possible without naming them again? and then do the substraction?
have a nice Friyay

採用された回答

Kevin Holly
Kevin Holly 2021 年 8 月 27 日
編集済み: Kevin Holly 2021 年 8 月 27 日
is this what you are looking for?
idx=logical(idx);
for i = 5:10
[X,Y]= meshgrid(T2.(i),T.(i));
C = X(idx);
D = Y(idx);
delta = (C - D);
T(i-4).table = table(D,C,delta);
end
  4 件のコメント
Kevin Holly
Kevin Holly 2021 年 8 月 31 日
NewTable = []
for i =1:5
M = table2array(T(i).table) %table(D,C,delta);
NewTable = [NewTable M]
end
FinalTable = array2table(NewTable,"VariableNames",["D1","C1","delta1","D2","C2","delta2","D3","C3","delta3","D4","C4","delta4","D5","C5","delta5"]);
or
idx=logical(idx);
M = [];
for i = 5:10
[X,Y]= meshgrid(T2.(i),T.(i));
C = X(idx);
D = Y(idx);
delta = (C - D);
M = [M D,C,delta]
end
t = array2table(M,"VariableNames",["D1","C1","delta1","D2","C2","delta2","D3","C3","delta3","D4","C4","delta4","D5","C5","delta5"]);
You can also generate a string of variable names, which you can automate as well if you just want to add numbers to them.
DulceEien
DulceEien 2021 年 9 月 2 日
thank you so much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by