フィルターのクリア

Find instances in workspace by their properties

6 ビュー (過去 30 日間)
Piment
Piment 2014 年 3 月 30 日
コメント済み: per isakson 2014 年 4 月 3 日
I have several instances of different classes in workspace, and I want to first get the instances instantiated from one class and then find the instances that have the same string property, I tried to add following method in class, but it doesn't return anything.
Or is there any easier way to find variables and get specific property values in workspace in this case? Thanks in advance.
function [ val ] = getInstance()
w = whos();
idx = strcmp({w.class}, 'xxx'); % index of instances of the same class in workspace
n = w(idx);
for k = 1 : size(n, 1)
f = evalin('base', n(k, 1).name); % iterate through those instances
if strcmp(f.propertyName1, 'yyy') % find the instances of specific property string value
t.(f.propertyName2) = f.propertyName3; % get property value and store in a struct
else
end
val = t;
end
  1 件のコメント
per isakson
per isakson 2014 年 4 月 3 日
Shouldn't
w = whos();
read
w = evalin( 'base', 'whos()' );
?

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

回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by