Replacing values in a matrix by specified values
3 ビュー (過去 30 日間)
古いコメントを表示
Carolin Brueckmann
2015 年 6 月 10 日
コメント済み: Carolin Brueckmann
2015 年 6 月 13 日
Hi there,
I have a three dimensional array of simulated data (dimensions are 10000,16,312 or #trials, TimeSeries, horizons). I would like to replace values above / below a pre-specified threshold with the threshold values. I have calculated the threshold values for each individual time series in MinAcceptableVal(:,i) and MaxAcceptableVal(:,i). When I run the code I do not receive an error message, but the values above the threshold are not cut off.
for i=1:nIndices
simulatedReturnsEVT1(simulatedReturnsEVT1(:,i,:)<MinAcceptableVal(:,i))=MinAcceptableVal(:,i);
simulatedReturnsEVT1(simulatedReturnsEVT1(:,i,:)>MaxAcceptableVal(:,i))=MaxAcceptableVal(:,i);
end
I have tried to use the code in a different form (see below) before and it worked perfectly. Matlab seems to be having problems with me introducing different cutoff levels for the different time series variables (i).
simulatedReturnsEVT1(simulatedReturnsEVT1<-1)=-1;
simulatedReturnsEVT1(simulatedReturnsEVT1>1)=1;
I would be very happy about any Hints!
Best, Carolin
2 件のコメント
Rong Yu
2015 年 6 月 10 日
I also think it is a dimensional issue. You could try to create a one-dimensional time series of your threshold values instead of two-dimensional.
for i=1:nIndices
simulatedReturnsEVT1(simulatedReturnsEVT1(:,i,:)<MinAcceptableVal(i))=MinAcceptableVal(i);
simulatedReturnsEVT1(simulatedReturnsEVT1(:,i,:)>MaxAcceptableVal(i))=MaxAcceptableVal(i);
end
採用された回答
Image Analyst
2015 年 6 月 10 日
Assign simulatedReturnsEVT1(:,i,:)>MaxAcceptableVal(:,i) to a variable and see what the dimension are.
indexesToClip = simulatedReturnsEVT1(:,i,:) > MaxAcceptableVal(:,i);
theSizes = size(indexesToClip)
You're basically taking a slice (plane) out of the 3D volume and comparing it to a value. So it might be a 2D array. On the other hand, it might be a N-by-1-by-M array, which I think should be okay. But if it's N-by-M, then that would be a problem.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!