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!