Replacing values in a matrix by specified values
조회 수: 2 (최근 30일)
이전 댓글 표시
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!