Show certain value in Cell array
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2017-4-4
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));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!