Show certain value in Cell array
3 views (last 30 days)
Show older comments
David du Preez
on 4 Apr 2017
Commented: David du Preez
on 4 Apr 2017
Hi. I have the following code which only opens and reads files depending on the file size then the variable output for each file is done in same cell array;
files = dir('D:\MLS_2\2008\v03');
% Loop for each file
for i = 1:length(files)
if files(i).bytes > 50000
filename = files(i).name;
% display names that are read
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-GEOS5/Data Fields/L2gpValue';
data_id = H5D.open(file_data,DATAFIELD_NAME);
% Time component
TIME_NAME='HDFEOS/SWATHS/O3 column-GEOS5/Geolocation Fields/Time';
time_id = H5D.open(file_data,TIME_NAME);
% Variables wanted
data1{i} =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{i} =datestr(datevec(datenum(1993,1,1,0,0,0)+time(1)/86400));
end
end
Some of the variable output looks like this[228.069580078125;226.937240600586;228.856262207031]. How do I only display the left most value in the cell array.
0 Comments
Accepted Answer
Image Analyst
on 4 Apr 2017
I'm not sure which variable you're talking about, but if [228.069580078125;226.937240600586;228.856262207031] is the contents of some particular cell you're looking at, let's call it thisCell, then to print it out to the command window you'd do
thisCell = ..... whatever ......
thisCellContents = cell2mat(thisCell); % Convert contents into column vector of N doubles.
fprintf('The first number = %f\n', thisCellContents(1));
More Answers (0)
See Also
Categories
Find more on Workspace Variables and MAT Files 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!