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!