Show certain value in Cell array

조회 수: 3 (최근 30일)
David du Preez
David du Preez 2017년 4월 4일
댓글: David du Preez 2017년 4월 4일
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.

채택된 답변

Image Analyst
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));
  댓글 수: 1
David du Preez
David du Preez 2017년 4월 4일
Sorry. I should I have said that it is for the data1 variable.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile 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!

Translated by