Constraints
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (2개)
the cyclist
2011년 10월 7일
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
Andrei Bobrov
2011년 10월 7일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!