Compare values in a table to a set of criteria

1 visualización (últimos 30 días)
Alice
Alice el 2 de Oct. de 2015
Respondida: Joseph Cheng el 2 de Oct. de 2015
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.

Respuestas (1)

Joseph Cheng
Joseph Cheng el 2 de Oct. de 2015
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)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by