How to run function between each row

2 ビュー (過去 30 日間)
Povilas Tarailis
Povilas Tarailis 2021 年 2 月 24 日
コメント済み: Rik 2021 年 2 月 24 日
Hi all. I have a matrix 7-by-256 and I need to run my funtion between each row like this: row1 row2; row1 row3; row 1 row4; etc... And save the results.
How do I specified that in for loop?

回答 (1 件)

Rik
Rik 2021 年 2 月 24 日
pairs=nchoosek(1:size(data,1),2);
for n=1:size(pairs,1)
row_a=data(pairs(n,1),:);
row_b=data(pairs(n,2),:);
%calculate results here
end
  2 件のコメント
Povilas Tarailis
Povilas Tarailis 2021 年 2 月 24 日
I'm completely new with matlab, so maybe you can walkthrough a bit. I don't understand what are and what happens in row_a and row_b
Rik
Rik 2021 年 2 月 24 日
On those lines I index the 7x256 array so you have two variables, each containg 256 values. That way you can do the calculations you need. In the first iteration row_a will contain the first row and row_b will contain the second row. The next iteration row_b will contain the third row, etc.
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by