フィルターのクリア

Find specific range in a table

14 ビュー (過去 30 日間)
Pouyan Sadeghian
Pouyan Sadeghian 2021 年 6 月 2 日
コメント済み: Star Strider 2021 年 6 月 3 日
Hi,
I want to find a specific range in my table.
For example I have a table like this called table:
Var1 Label MaxPosition MinValue
____ _________________ ___________ ________
678 {'Image0029.bmp'} 38 0
679 {'Image0029.bmp'} 51 0
680 {'Image0030.bmp'} 40 0
681 {'Image0030.bmp'} 47 0
682 {'Image0030.bmp'} 51 0
683 {'Image0030.bmp'} 54 0
684 {'Image0031.bmp'} 42 0
685 {'Image0031.bmp'} 53 0
686 {'Image0031.bmp'} 57 0
687 {'Image0032.bmp'} 44 0
688 {'Image0032.bmp'} 55 0
689 {'Image0032.bmp'} 59 0
690 {'Image0033.bmp'} 45 0
I want to display just the values greater than 40 and less than 50 of the column MaxPosition. I tried the code but it doesnt work and I dont know why. I searched in the forums and help and dont find a solution for my problem.
This is the code I use:
NewTable = varfun(@(x)(x>40) & (x<50),table,'GroupingVariables','MaxPosition')
If it is uesfull the error:
Error using tabular/varfun>dfltErrHandler (line 434)
Applying the function '@(x)(x>40)&(x<50)' to the 1st group in the variable 'Label' generated the following error:
Undefined function 'gt' for input arguments of type 'cell'.
Error in tabular/varfun>@(s,varargin)dfltErrHandler(grouped,funName,s,varargin{:}) (line 183)
errHandler = @(s,varargin) dfltErrHandler(grouped,funName,s,varargin{:});
Error in tabular/varfun (line 230)
outVals{igrp} = errHandler(s,inArg);
Error in calculation (line 27)
MaxV = varfun(@(x)(x>40) & (x<50),sortedTablelup,'GroupingVariables','MaxPosition')
I would be happy if someone could help me.
Best
Pouyan

採用された回答

Star Strider
Star Strider 2021 年 6 月 2 日
Try this —
T1 = cell2table({678. {'Image0029.bmp'}, 38 0
679 {'Image0029.bmp'} 51 0
680 {'Image0030.bmp'} 40 0
681 {'Image0030.bmp'} 47 0
682 {'Image0030.bmp'} 51 0
683 {'Image0030.bmp'} 54 0
684 {'Image0031.bmp'} 42 0
685 {'Image0031.bmp'} 53 0
686 {'Image0031.bmp'} 57 0
687 {'Image0032.bmp'} 44 0
688 {'Image0032.bmp'} 55 0
689 {'Image0032.bmp'} 59 0
690 {'Image0033.bmp'} 45 0}, 'VariableNames',{'Var1','Label','MaxPosition','MinValue'})
T1 = 13×4 table
Var1 Label MaxPosition MinValue ____ _________________ ___________ ________ 678 {'Image0029.bmp'} 38 0 679 {'Image0029.bmp'} 51 0 680 {'Image0030.bmp'} 40 0 681 {'Image0030.bmp'} 47 0 682 {'Image0030.bmp'} 51 0 683 {'Image0030.bmp'} 54 0 684 {'Image0031.bmp'} 42 0 685 {'Image0031.bmp'} 53 0 686 {'Image0031.bmp'} 57 0 687 {'Image0032.bmp'} 44 0 688 {'Image0032.bmp'} 55 0 689 {'Image0032.bmp'} 59 0 690 {'Image0033.bmp'} 45 0
T2 = T1((T1.MaxPosition>40) & (T1.MaxPosition<50),:)
T2 = 4×4 table
Var1 Label MaxPosition MinValue ____ _________________ ___________ ________ 681 {'Image0030.bmp'} 47 0 684 {'Image0031.bmp'} 42 0 687 {'Image0032.bmp'} 44 0 690 {'Image0033.bmp'} 45 0
.
  2 件のコメント
Pouyan Sadeghian
Pouyan Sadeghian 2021 年 6 月 3 日
Hi Star,
thanks. It works!
Best
Star Strider
Star Strider 2021 年 6 月 3 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeElectromechanical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by