Matlab:查找并替换具有 34 个字段的 1*1 结构中的缺失值
Matlab: find and replace missing value in a 1*1 struct with 34 fields
在 Matlab 中,我有一个包含 34 个字段的 1*1
结构。每个字段本身就是一个 3d 数组。下面附上它的照片。
我想要一个代码来在这个结构 的 的任何地方找到 -9.969209968386869e+36
并将其替换为 NaN
。
here is a picture of it
提前致谢
您可以使用下面的代码
x = struct2cell(mystruct);
for i=1:34
x{i}(x{i} == -9.969209968386869e+36)= nan
end
mystruct = cell2struct(x, fieldnames(x));
这可能比单元格转换占用更少的内存:
如果你的结构被称为x
,
names = fieldnames(x); % gets the names of the items in the struct
for i = 1:numel(names)
x.(names{i})(x.(names{i})==-9.969209968386869e+36) = nan('single');
end
在 Matlab 中,我有一个包含 34 个字段的 1*1
结构。每个字段本身就是一个 3d 数组。下面附上它的照片。
我想要一个代码来在这个结构 的 的任何地方找到 -9.969209968386869e+36
并将其替换为 NaN
。
here is a picture of it
提前致谢
您可以使用下面的代码
x = struct2cell(mystruct);
for i=1:34
x{i}(x{i} == -9.969209968386869e+36)= nan
end
mystruct = cell2struct(x, fieldnames(x));
这可能比单元格转换占用更少的内存:
如果你的结构被称为x
,
names = fieldnames(x); % gets the names of the items in the struct
for i = 1:numel(names)
x.(names{i})(x.(names{i})==-9.969209968386869e+36) = nan('single');
end