Compare values in a table to a set of criteria
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi so I have a table with a variable rt.
I want to create a new variable which tells me if the values in rt are within a certain range (so if values are 0.3<rt<3).
I've tried the notation: out=0.3<rt<3 but I get an error message because of the type rt is (it's a cell).
Is there a way around this? Is there anyway that I can identify in a new variable which values fit my range/ criteria and which fall outside the range?
Any suggestions about how to tackle this would be greatly appreciated.
Thanks.
댓글 수: 0
답변 (1개)
Joseph Cheng
2015년 10월 2일
matlab does not do conditionals like that. you'll need to use the logical operands to accomplish this.
so if it isn't a cell you'd accomplish this by the example:
rt= magic(5)
lt10gt4 = rt<10 & rt>4
where the resulting 1's are when rt is between 4 and 10. 0's when rt is outside of the specified range.
to accomplish this if rt is a cell you can use the function cellfun like i have below
rt = 5*rand(10,10);
rtcell = mat2cell(rt,ones(1,size(rt,1)),ones(1,size(rt,2)));
cond = cellfun(@(cellmat) cellmat>.3&cellmat<3,rtcell,'uniformOutput',false)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!