Zero out values in multiple fields of a struct
조회 수: 15 (최근 30일)
이전 댓글 표시
Suppose I have
S.ABC0500 = struct('Keys',[1:9],'Values',rand(1,9));
S.ABC0800 = struct('Keys',[1:9],'Values',rand(1,9));
S.ABC0900 = struct('Keys',[1:9],'Values',rand(1,9));
S.Title = 'MyData';
S.Date = datetime('today');
How can I efficiently set all the values to zero? That is, I want to do
S.ABC0500.Values = zeros(1,9);
S.ABC0800.Values = zeros(1,9);
S.ABC0900.Values = zeros(1,9);
The number of ABC variables is large.
댓글 수: 1
Stephen23
2023년 5월 5일
"How can I efficiently set all the values to zero"
With more suitable data design: don't force meta-data into fieldnames. A non-scalar structure would likely be better:
채택된 답변
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!