Azzera filtri
Azzera filtri

Constraints

2 visualizzazioni (ultimi 30 giorni)
Melissa
Melissa il 7 Ott 2011
Good Morning All,
I was wondering how it would be possible to apply constraints to a matrix. I will have a large matrix full of answers but I want to limit the answers.
For example let x,y,z be columns 1,2,3 of the matrix and i want to set limitations to 5<x<10, 0<y<4, and 6<z<12.
Any suggestions?
Thanks,
Mel

Risposte (2)

the cyclist
the cyclist il 7 Ott 2011
What do you want to do with the values that lie outside those limits? If you want to cap them, then you could do:
>> x(x>10) = 10;
>> x(x<5) = 5;
and similar for y and z.
If "A" is the matrix and x is the first column, as you say, then this means something like:
>> A(A(:,1)>10,1) = 10;
etc.

Andrei Bobrov
Andrei Bobrov il 7 Ott 2011
xyz = randi([0 28],15,3)
llt = [5 0 6]
rlt = [10 4 12]
id = bsxfun(@lt,llt,xyz)&bsxfun(@gt,rlt,xyz)
out = arrayfun(@(i1)xyz(id(:,i1),i1),1:size(xyz,2),'un',0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by