How do you output both variable values and names in a function?
2 ビュー (過去 30 日間)
古いコメントを表示
I'm writing a code that converts epoch time to something akin to date time. It gives me a 2 digit year, day of the year, and fraction of the day. I'm working on converting the fraction of the day into hours, minutes and seconds. I've attached my code below, and my question pertains to the last line, when I have time = [t_h; t_m; t_s], is it possible to add something so I can differentiate hours, minutes, and seconds? When I call the function in my script I want to leave it without a semi colon so that I don't have to overcomplicate my code with additional lines using disp or fprintf because this is just an intermediate step.
function [year, day, time] = Epoch_calc(recorded_date)
%EPOCH_CALC find year, day, and time for tle data
year = floor(recorded_date/1000);
y = (recorded_date/1000 - floor(recorded_date/1000))*1000;
day = floor(y);
x = (y - floor(y))*86400;
t_h = floor(x/3600);
t_m = floor((x - t_h*3600)/60);
t_s = (x - t_h*3600 - t_m*60);
time = [t_h; t_m; t_s];
end
2 件のコメント
Paul
2023 年 11 月 21 日
Hi Bryce,
Can you clarify what "differentiate hours, minutes, and seconds" means? As it stands, I don't understand how that relates to whether or not time is defined as a column vector (with semicolons) or a row vector (without semicolons), assuming that t_h, t_m, and t_s are scalars.
Cris LaPierre
2023 年 11 月 21 日
Could your provide an example of what your input data is, and what the correct date should be (i.e. what is the epoch)?
回答 (1 件)
Chunru
2023 年 11 月 21 日
You can consider to use struct which has field names.
t = Epoch_calc(20231121)
function t = Epoch_calc(recorded_date)
%EPOCH_CALC find year, day, and time for tle data
year = floor(recorded_date/1000);
y = (recorded_date/1000 - floor(recorded_date/1000))*1000;
day = floor(y);
x = (y - floor(y))*86400;
t.h = floor(x/3600);
t.m = floor((x - t.h*3600)/60);
t.s = (x - t.h*3600 - t.m*60);
% time = [t_h; t_m; t_s];
end
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!