Replacing values in a matrix by specified values

3 views (last 30 days)
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 Comments
James Tursa
James Tursa on 10 Jun 2015
What are the dimensions of MinAcceptableVal and MaxAcceptableVal?
Rong Yu
Rong Yu on 10 Jun 2015
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

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 10 Jun 2015
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 Comment
Carolin Brueckmann
Carolin Brueckmann on 13 Jun 2015
Hi Image Analyst,
thanks a lot for your help! I was able to implement the code now and it works perfectly :-)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!