Constraints
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (2)
the cyclist
on 7 Oct 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.
0 Comments
Andrei Bobrov
on 7 Oct 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)
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!