How to convert zero to 'Nan' for multiple dot mat file containing 1d data
1 view (last 30 days)
Show older comments
Yared Daniel on 25 May 2021
Commented: Jan on 25 May 2021
I have several dot mat files, each files contains 1d array data, some of the data has zero value, and I want to convert zero values to ‘Nan’ for each dot mat files using for loop. I did for a single file using the following commands and it successfully converted zeros to Nan.
>> A(A ==0) = NaN;
However performing for each file one by one like this is a kind of tiresome since I have thousands of files. Please forward any trick to solve this problem.
Thanks for your Help
Matt J on 25 May 2021
Edited: Matt J on 25 May 2021
save( strrep(fn,'NormFHR','MRN'), 'A')
Jan on 25 May 2021
@Matt J: Look into the source code of ls() . It calls dir() also and convertes the field "name" to a char. The output is padded, such that all lines have the same number of columns. Onbatining the lines later forward the padded char vectors as input to load. Therefore ls is löess efficient than using the unpadded char vectors directly:
fileList = dir('NormFHR*.mat');
for k = 1:numel(fileList)
fn = fileList(k).name;
More Answers (0)
Find more on Represent Data 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!