I want to take the change of time from excel rows and add it to a user prompted input in MatLab
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Lets say I have rows of time data in excel that are [1, 2, 3, 4, 5, 6, 7] seconds. I have a user input command asking the user to ask for a time of day (say 13:00 military time). I want to take the time difference in row 1 and row 2 from the excel file and add that difference to the user inputed time.
I have all of the excel data inputted into MatLab already so I really just need an equation that would allow me to do this.
0 Commenti
Risposte (1)
Rahul
il 14 Ott 2024
I understand that you are reading time data fropm an excel file and also asking for user input in MATLAB for a particular time. Additionally you wish to obtain an equation to take the difference of time data from certain rows and add that difference to the user input.
You can consider the following example:
timeData = [1, 2, 3, 4, 5, 6, 7];
% Here I am considering this example for time data as also given in the question.
% I have also considered this time data to be in denomination of Seconds.
% You can change that accordingly.
timeDifference = timeData(2) - timeData(1);
userTimeStr = '13:00'; % Considering this example for user input
userTime = datetime(userTimeStr, 'InputFormat', 'HH:mm');
% Converting time data to datetime format using 'datetime' function
% Using 'seconds' function to obtain the time difference as a 'duration'
timeDifferenceDuration = seconds(timeDifference);
Now 'userTime' and 'timeDifferenceDuration' are both 'datetime' objects which can simply be added directly.
% Adding the time difference to the user input time
newTime = userTime + timeDifferenceDuration;
% Using 'datestr' to display the 'datetime' object 'newTime'
disp(['New time is: ', datestr(newTime, 'HH:MM:SS')]);
As mentioned, I have considered the time data from the excel in seconds. If you require any other denomination, you can use functions like 'minutes' or 'hours' as per your requirements.
You can refer to the following MathWorks documentations to know more about these functions:
Hope this helps! Thanks.
0 Commenti
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!