フィルターのクリア

How to extract property values from an object array and put it into a new array?

8 ビュー (過去 30 日間)
Nirmal Hirani
Nirmal Hirani 2022 年 10 月 13 日
編集済み: Matt J 2022 年 10 月 13 日
classdef Datatest
properties (SetAccess = 'public' ,GetAccess = 'public')
Name
end
end
% creating 4 objects of the class 'Datatest'
x1 = Datatest();
x2 = Datatest();
x3 = Datatest();
x4 = Datatest();
% Changing the name of each objects property
x1.Name = 'test1';
x2.Name = 'test2';
x3.Name = 'test3';
x4.Name = 'test4';
% array of objects
list = [x1 x2 x3 x4]
dropDown = zeros(1,4)
for i=1:4
dropDown(i) = list(i).Name
end
i would like to create an array called 'dropDown' and extract all the names of objects from the object list. I tried this code which is giving me an arror "Unable to perform assignment because the left and right sides have a different number of elements."

採用された回答

Matt J
Matt J 2022 年 10 月 13 日
編集済み: Matt J 2022 年 10 月 13 日
% Changing the name of each objects property
x1.Name = 'test1';
x2.Name = 'test2';
x3.Name = 'test3';
x4.Name = 'test4';
list = [x1 x2 x3 x4];
dropDown=string({list.Name})
dropDown = 1×4 string array
"test1" "test2" "test3" "test4"

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by