Stop overwriting output variables
1 view (last 30 days)
Show older comments
David du Preez
on 2 Apr 2017
Answered: Star Strider
on 2 Apr 2017
Hi. I have the following code which only opens and reads files depending on the file size.
% File directory
files = dir('D:\MLS_2\2006\v04')
% Loop for each file
for i = 1:length(files)
if files(i).bytes > 50000
filename = files(i).name;
disp(filename)
%open files with data
file_data = H5F.open(filename,'H5F_ACC_RDONLY','H5P_DEFAULT');
%Data field for data wanted
DATAFIELD_NAME = 'HDFEOS/SWATHS/O3 column/Data Fields/L2gpValue';
data_id = H5D.open(file_data,DATAFIELD_NAME);
%Time component
TIME_NAME='HDFEOS/SWATHS/O3 column/Geolocation Fields/Time';
time_id = H5D.open(file_data,TIME_NAME);
%Variables wanted
data1=H5D.read (data_id,'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL', ...
'H5P_DEFAULT');
time=H5D.read(time_id,'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL',...
'H5P_DEFAULT');
time1lvl=datestr(datevec(datenum(1993,1,1,0,0,0)+time(1)/86400));
end
end
How can I stop the output variables (data1, time and time1lvl) that I want from being over-written each time. I also want to combine data1 and time1lvl.
0 Comments
Accepted Answer
Star Strider
on 2 Apr 2017
I would save them as cell arrays:
Example:
data1{i} = H5D.read (data_id,'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL', ...
'H5P_DEFAULT');
time{i} = H5D.read(time_id,'H5T_NATIVE_DOUBLE', 'H5S_ALL', 'H5S_ALL',...
'H5P_DEFAULT');
time1lvl{i} = datestr(datevec(datenum(1993,1,1,0,0,0)+time(1)/86400));
Note the curly brackets ‘{}’ denoting cell array indexing.
0 Comments
More Answers (0)
See Also
Categories
Find more on Point Cloud Processing 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!