Changing variabele from minutes to seconds and cell to double?
3 次查看(过去 30 天)
显示 更早的评论
I measured data and it transferred into an Excel file. I loaded the data, but got the variable of the timestamp in a cell and in mm:ss. I want to change the file into a double and in seconds, so I can plot it against several other variables. Those are in a double size, so I find it weird that this one is different. Can somebody help me out please?
P.S. It's a 467x1 cell, which looks somewhat like this:
'00:01'
'00:04'
'00:07'
'00:10'
'00:12'
'00:15'
'00:17'
0 个评论
采纳的回答
Animesh
2023-7-1
Certainly! In MATLAB, you can convert the timestamp data from the cell array into double values representing seconds. Here's how you can do it:
% Assuming your timestamp data is stored in a cell array called 'timestamps'
timestamps = {'00:01', '00:04', '00:07', '00:10', '00:12', '00:15', '02:17'};
% Initialize an array to store the converted values
timestamps_seconds = zeros(size(timestamps));
% Iterate over each timestamp and convert it to seconds
for i = 1:numel(timestamps)
% Split the timestamp string into minutes and seconds
time_parts = split(timestamps{i}, ':');
% Convert minutes and seconds to double values
minutes = str2double(time_parts{1});
seconds = str2double(time_parts{2});
% Calculate the total time in seconds
total_seconds = minutes * 60 + seconds;
% Store the result in the array
timestamps_seconds(i) = total_seconds;
end
% Now you have the timestamps in double format, representing seconds
disp(timestamps_seconds);
This code snippet takes your cell array of timestamps, splits each timestamp into minutes and seconds, converts them to double values, and calculates the total time in seconds. The resulting timestamps in seconds are stored in the timestamps_seconds array.
You can now use the timestamps_seconds array to plot against your other variables.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!