필터 지우기
필터 지우기

Constraints

조회 수: 1 (최근 30일)
Melissa
Melissa 2011년 10월 7일
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

답변 (2개)

the cyclist
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.

Andrei Bobrov
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)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by