Effacer les filtres
Effacer les filtres

Compare values in a table to a set of criteria

3 vues (au cours des 30 derniers jours)
Alice le 2 Oct 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.

Réponses (1)

Joseph Cheng
Joseph Cheng le 2 Oct 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)


En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by