Replacing values in a matrix by specified values

1 vue (au cours des 30 derniers jours)
Carolin Brueckmann
Carolin Brueckmann le 10 Juin 2015
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 commentaires
James Tursa
James Tursa le 10 Juin 2015
What are the dimensions of MinAcceptableVal and MaxAcceptableVal?
Rong Yu
Rong Yu le 10 Juin 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

Connectez-vous pour commenter.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by