所有组合的Matlab Loop [英] Matlab Loop of all combinations
问题描述
我是Matlab的新手,这似乎超出了我的范围.提前感谢您的帮助.
Im new to Matlab and this seems to be beyond me. Appreciate the help and thanks in advance.
- 基本上,我有一个带有列标题的多列数据集.列号可能因数据集而异.
- 需要遍历所有列组合(例如A + B,A + C .... B + C,B + D ...等)并运行公式(在这种情况下,它是一个相关公式但随后可能是另一个公式).
- 如果特定组合返回"true",则将返回该对的列标题.
如果能为我指明正确的方向,将不胜感激.
Would appreciate if you could point me in the right direction.
谢谢.
推荐答案
使用nchoosek
获取所有成对的列:
Use nchoosek
to get all pairs of columns:
pairs_columns = nchoosek(1:m, 2);
pairs = {};
for pair = 1:size(pairs_columns,1)
flag = your_correlation_test(data(:,pairs_columns(pair,1)), data(:,pairs_columns(pair,2)));
if flag
pairs{end+1,1} = data_header(pairs_columns(pair,1));
pairs{end,2} = data_header(pairs_columns(pair,2)); %// Note that you don't need end+1 anymore as the previous line will have already increased the number of rows in the vector
end
end
m
是您的列数
your_correlation_test
是您的返回布尔结果的测试函数
your_correlation_test
is your test function that returns a Boolean result
data
是您的数据集(我假设您可以按列号编制索引?)
data
is your dataset (which I'm assuming you can index by column number?)
data_header
是占位符,用于根据列号从数据集中获取标题的任何正确方法.抱歉,我对Matlab中的数据集不是很熟悉
data_header
is a place holder for whatever the correct way to get the header is from your dataset based on the column number. Sorry I'm not very familiar with datasets in Matlab
这篇关于所有组合的Matlab Loop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!