Subscript indices must either be real positive integers or logicals in bsxfun

1 回表示 (過去 30 日間)
Matthew Zelko
Matthew Zelko 2016 年 1 月 19 日
コメント済み: Guillaume 2016 年 1 月 19 日
Hi there,
Had a look at various others posts that include this error message but cannot find what is missing from my code. Feel like I am brute forcing this by as it stands I have
T 19081 x 22 double % Raw Data values
StdTimedEdit 1 x 22 double % Standard Deviation values for each column
MeanTimedEdit 1 x 22 double % Means for each column
StDIndexFull 19081 x 22 logical % Logical Index for which values I want to run the bxs function on
I am trying to do run a bxsfun to replace values outside 2 standard deviations from the mean for each column with 'NaN', but only on the values that equal 1 in the logical StDIndexFull. Currently it looks as such:
T(bsxfun(@lt, T(T(StdIndexFull)), (MeanTimedEdit + 2*StDsTimedEdit)) ...
& bsxfun(@gt, T(T(StdIndexFull)), (MeanTimedEdit - 2*StDsTimedEdit)))= NaN;
This returns the following error:
Subscript indices must either be real positive integers or logicals.
Any assistance or opinions would be muchly appreciated
Matt

採用された回答

Guillaume
Guillaume 2016 年 1 月 19 日
編集済み: Guillaume 2016 年 1 月 19 日
As Star said, one of your problem is the use of T to index into itself. That makes no sense, I'm not sure what you intended with that.
In addition, your logic has gone a bit wrong on where to use the logical array. You want to find the values that:
  1. are outside the standard deviation (using bsxfun indeed) AND
  2. correspond to true in the logical array
This is written as:
(bsxfun(@lt, T, MeanTimedEdit - 2*StDsTimedEdit) | bsxfun(@gt, T, MeanTimedEdit + 2*StDsTimedEdit)) ... %part 1
& StdIndexFull %part 2
So the replacing is written as:
T((bsxfun(@lt, T, MeanTimedEdit - 2*StDsTimedEdit) | bsxfun(@gt, T, MeanTimedEdit + 2*StDsTimedEdit)) & StdIndexFull) = nan;
  2 件のコメント
Matthew Zelko
Matthew Zelko 2016 年 1 月 19 日
Thanks for this Guillaume, apart from missing 't' after @gt, this works great!
Apparently I didn't realise the bxsfun could use the Index as a stand alone criteria.
Thanks again to both yourself and Star Strider.
Guillaume
Guillaume 2016 年 1 月 19 日
Sorry about the typo, now fixed.
No, bsxfun is not using the index as a stand alone criteria. What is happening is that the two bsxfun are generating a logical array telling you which number is outside the standard deviation (step 1). It does not use your index array at all. That step 1 logical array is then combined with your index logical array using normal boolean operation.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by