How to assign objects to array?
古いコメントを表示
% https://de.mathworks.com/help/rf/ref/sparameters.html
I'm using the RFToolbox and have a bunch of S-Parameters which I import from Touchstone files.
f = "path-to-touchstone-file.s2p";
sobj = sparameters(f);
sobj.Parameters
sobj.Frequencies
sobj.Impedance
Now I want to create an array which holds multiple objects and is accessible by index.
f = ["path-to-file-1",...
"path-to-file-2",...
"path-to-file-3"...
];
for i = 1:numel(f)
sobj(i) = sparameters(f(i));
end
sobj(1).Parameters
sobj(1).Frequencies
sobj(1).Impedance
This does not work. I don't know how to create an array, which can hold the objects returned from sparameters(). I get the following output:
% Unable to perform assignment because value
% of type 'sparameters' is not convertible to
% 'cell'.
%
% Error in example (line 7)
% sobj(i) = sparameters(f(1));
%
% Caused by:
% Error using cell
% Conversion to cell from sparameters is
% not possible.
If I create a single S-Parameter object first I'm able to add more objects afterwards, but I'd like to know how to preallocate the proper data structure.
f = ["path-to-file-1",...
"path-to-file-2",...
"path-to-file-3"...
];
sobj = sparameters(f(1));
for i:numel(f)
sobj(i) = sparameters(f(i));
end
5 件のコメント
Mario Malic
2023 年 4 月 17 日
What is the output of this?
f = "path-to-touchstone-file.s2p";
sobj = sparameters(f);
whos sobj
Jan
2023 年 4 月 17 日
Mario Malic
2023 年 4 月 17 日
Jan
2023 年 4 月 17 日
Mario Malic
2023 年 4 月 17 日
Yes, for some reason sobj was treated as cell array and you were indexing into it the wrong way. This would have worked.
for i:numel(f)
sobj{i} = sparameters(f(i));
end
You are welcome.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Model Compatibility についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!