How can I round double-values down in a Matlab function block in Simulink?
Mostrar comentarios más antiguos
I want to generate a timestamp from the unix time, which is delivered by an external C-function in a MATLAB function block in a simulink project. I'm trying to round the double values for hours, minutes and seconds to the integer in front of the decimal point. However, the function always rounds to the nearest integer. So my hours round up after 30 minutes and my minutes round up after 30 seconds. I tried the floor() function already, but it leaves the value unaltered. I tried to set up the fimath()-function in the model explorer and at the beginning of the script, but I guess it only changes fixed point values? (duh)
I have no idea what else to try. Where is my mistake?
(...)
leftover_seconds = leftover_seconds - (sum_days + days - 1)*24*3600; %here I calculate the elapsed seconds of the current day, which are correct
hours = leftover_seconds/3600;
minutes = (leftover_seconds - hours*3600)/60;
seconds = leftover_seconds - ((hours*3600) + (minutes*60));
(...)
I deleted the floor() functions in front of each line, because it didn't do anything.
I appreciate any tips. Thank you!
Respuesta aceptada
Más respuestas (1)
Sayyed Ahmad
el 4 de Jun. de 2019
I would programming like this:
x=strsplit(datestr(now,'YYYY-mm-DD-HH-MM-ss'),'-') % instead of now you can use your time from external C++ program
year=num2str(x{1})
mount=num2str(x{2})
day=num2str(x{3})
hour=num2str(x{4})
minute=num2str(x{5})
secound=num2str(x{6})
instead of
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!