필터 지우기
필터 지우기

Check if string matches many possibilities or check if doesn't match few possibilities.

조회 수: 3 (최근 30일)
Let's say I have a set of validated strings: {'B2D2', 'CPS4', 'R2D2', 'RB2D2', 'SB2D2', 'T2D2'}. And I want to proceed based on whether the input string matches any of the following: {'B2D2', 'R2D2', 'RB2D2', 'SB2D2'}. Which would be a faster invocation of strcmp()?
if any(strcmp(params.Results.eletype, {'B2D2', 'R2D2', 'RB2D2', 'SB2D2'}))
Or, check if it DOES NOT match the supplementary possibilites:
if ~any(strcmp(params.Results.eletype, {'CPS4', 'T2D2'}))
I ask this from a high-performance standpoint. I'm trying to cut computation time wherever I reasonably can here.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 2일
편집: Ameer Hamza 2020년 11월 2일
I guess that 2nd should be faster because it involve less comparisons; however, Instead of speculations, it is better to just profile the code: https://www.mathworks.com/help/matlab/matlab_prog/profiling-for-improving-performance.html.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by