필터 지우기
필터 지우기

filter an array of objects based on the value of a string property

조회 수: 6 (최근 30일)
tombola
tombola 2012년 3월 29일
Hi, if I have a class "Trade" with a property "Type".
Is there a way to easily filter an array of Trade objects based on say Type == "Cash"
I can filter on booleans easily, I just can't figure out strings.
Thanks for any help,
Tom.

답변 (1개)

Jacob Halbrooks
Jacob Halbrooks 2012년 3월 29일
You can create a logical mask using ARRAYFUN, where you execute a function on each object that returns true if the object is the desired type. You can then use that logical mask to return the desired objects. For example, assume that you have an array of objects "objArr" and you want to get the objects of Type "Cash". Then execute:
mask = arrayfun(@(x)strcmp(x.Type, 'Cash'), objArr);
objTypeCashArr = objArr(mask);

카테고리

Help CenterFile Exchange에서 Use Prebuilt MATLAB Interface to C++ Library에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by