How do I extract the Datetime array from the CSV ?
4 次查看(过去 30 天)
显示 更早的评论
I am trying to extract the Average Ice concentration and date time from the CSV file. I managed to extract the Average ice concentration, but for the date time it is extracting as individual cell arrays with datetime in eah cell as follows
I would want it to extract the datetime like this (from another project but cell2mat doesnot work here)
The cell2mat function doesnot work. I would want some recommendations on how to proceed.
The code is as follows
%% Importing data file
% Note: The text file has headers and two columns:
% Column 1 - example of entry: {[2010-12-16 0:00]}
% Column 2 - Ice concentration Min
% Column 3 - Ice concentration Average
% Column 4 - Ice concentration Max
%% Because these are two different data types, they need to be imported as a CELL ARRAY
B=readcell('Ice concentration data.csv'); % Note: The csv format is automatically recognized.
B(1:1,:) = []; % Removing top rows (headers)
%% From this array, we extract the Average Ice Concentration levels
% Average Ice Concentration levels - production of a one-column numeric matrix
average_ice_concentration_level = cell2mat(B(:,3));% Converting average ice concentration from numeric cell
% to numeric vector (matrix)
%% From the same array, we extract date, month, day
% Step 1: Production of a character vector matrix
date_ice_concentration = (B(:,1));
0 个评论
采纳的回答
Star Strider
2022-11-7
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1184228/Ice%20concentration%20data.csv')
T1.DateTime
VN = T1.Properties.VariableNames;
lgdstr = cellfun(@(x)strrep(x,'_','\_'), VN(2:end), 'Unif',0)
figure
plot(T1.DateTime, T1{:,2:end})
grid
legend(lgdstr, 'Location','best')
.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!