Finding the ratio of numbers in an array

14 ビュー (過去 30 日間)
Benjamin Cowen
Benjamin Cowen 2020 年 3 月 4 日
編集済み: Rik 2020 年 3 月 4 日
I access my array as:
data{1, i}(:,2)
So it is in the second column of data{1,i}
I have data in columns 3 and 4 already. I would like to make a column 5. I want column 5 to be the value in column 2 divided by the value in column 2 but 30 cells up. This means the first 30 values cannot be defined since we cannot compare to 30 cells prior. I keep trying this but I either get an array of zeros, or a single value. Can anyone help?
For instance, this does not work:
for j =31:1:1000
rois=data{1, i}(j,2)/data{1, i}(j-30,2)
end
  2 件のコメント
Prasobhkumar P. P.
Prasobhkumar P. P. 2020 年 3 月 4 日
Why step size is 100?shouldnt be 1?
Benjamin Cowen
Benjamin Cowen 2020 年 3 月 4 日
編集済み: Benjamin Cowen 2020 年 3 月 4 日
Yeah, it should be 1, sorry about that. I tried 1 at first and it got hung, so i assumed i was doing something wrong

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

回答 (1 件)

Rik
Rik 2020 年 3 月 4 日
編集済み: Rik 2020 年 3 月 4 日
rois=data{1, i}(31:end,2)./data{1, i}(1:(end-30),2);
In your current loop you are overwriting your result every iteration, you should have used indexing instead, skip the loop entirely.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by