MATLAB: Create a block table using script

blockmatlab functionscriptsimulink

I am trying to create a function that can create a block table that contain their Handle, FullName, BlockType, Parent by using struct. However each time I get enter a model name, it said
Error in createBlockTable (line 9)
tableStruct = struct(get(gcb), 'Handle', get(i), 'FullName');
Here is my code
function blockTable = createBlockTable(modelName)
load_system(modelName);
getBlock = find_system(modelName, 'FindAll', 'on', 'FollowLinks', 'on', 'LookUnderMasks', 'all', 'Type', 'Block');
blockCell = cell(1,length(getBlock));
for n = 1:length(getBlock)
for i = getBlock(n, 1)
tableStruct = struct(get(i), 'Name');
end
end
blockTable = assign(tableStruct, blockCell);
end
I am thinking that I mess up at line i = getBlock(:,1), but I do not know how to solve this problem. Thanks

Best Answer

I have solve the problem, thanks to @Fangjun Jiang that gave me some idea
copyModel = 'sldemo_fuelsys_copy';
blockTable = makeTable(copyModel);
save('blockTable.mat','blockTable');
function blockTable = makeTable(modelName)
load_system(modelName);
getBlock = find_system(modelName, 'FindAll', 'on', 'FollowLinks', 'on', 'LookUnderMasks', 'all', 'Type', 'Block');
blockCell = cell(1, length(getBlock));
for n = 1:length(getBlock)
structTable = struct('Handle', get(getBlock(n), 'Handle'), 'Name', ...
get(getBlock(n), 'Name'), ...
'Block_Type', get(getBlock(n), 'BlockType'), ...
'Parent', get(getBlock(n), 'Parent') );
blockCell{1, n} = structTable;
end
blockTable = blockCell;
end