Find and replace missing value in a 1*1 struct with 34 fields
4 views (last 30 days)
Show older comments
I have a 1*1 struct with 34 fields. every field is a 3d array by itself. A picture of it attached. I want to have a code to find -9.969209968386869e+36 in everywhere of this struct (including inside fields) and replace it with NaN.
thank you
1 Comment
Accepted Answer
Image Analyst
on 28 Oct 2019
How about (untested)
% Get all the field names with this structure.
fieldNames = fieldnames(precip)
for k = 1 : length(fieldNames)
thisFieldName = fieldNames{k}; % Get this field name.
thisField = precip.(thisFieldName); % Get the 3-D array.
% Use ismembertol() to look for the specified value.
indexes = ismembertol(thisField, whatever)
% Replace those locations with nans.
thisField(indexes) = nan;
% Put back into precip.
precip.(thisFieldName) = thisField;
end
2 Comments
Image Analyst
on 29 Oct 2019
Attach precip in a .mat file
save('answers.mat', 'precip');
then attach 'answers.mat' with the paper clip icon.
More Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!