Replacing values in a matrix by specified values

조회 수: 2 (최근 30일)
Carolin Brueckmann
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
James Tursa
James Tursa 2015년 6월 10일
What are the dimensions of MinAcceptableVal and MaxAcceptableVal?
Rong Yu
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
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.
  댓글 수: 1
Carolin Brueckmann
Carolin Brueckmann 2015년 6월 13일
Hi Image Analyst,
thanks a lot for your help! I was able to implement the code now and it works perfectly :-)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by