필터 지우기
필터 지우기

convert time from sample to second

조회 수: 10 (최근 30일)
cmcm
cmcm 2014년 6월 27일
댓글: cmcm 2014년 6월 28일
hello .. i have a simulink program, the solver is a fixed step type (with sample time 0.001), when the program run, i have a result as shown in figure below (the time axis in sample not second) ,,, this 300 sample is almost equal 10 real seconds, how to convert the time axis to seconds instead of samples (by using plot command if possible) ?
  댓글 수: 1
Image Analyst
Image Analyst 2014년 6월 28일
Original question (in case he edits it away like the others)
hello .. i have a simulink program, the solver is a fixed step type (with sample time 0.001), when the program run, i have a result as shown in figure below (the time axis in sample not second) ,,, this 300 sample is almost equal 10 real seconds, how to convert the time axis to seconds instead of samples (by using plot command if possible) ?

댓글을 달려면 로그인하십시오.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 6월 27일
te=0.001
xt=get(gca,'xtick')
set(gca,'xticklabel',arrayfun(@num2str,xt*te,'un',0))
  댓글 수: 4
cmcm
cmcm 2014년 6월 27일
this is the new figure... and it is absolutely wrong because now i have a time axis with 0.3 second and it should be 10 seconds
cmcm
cmcm 2014년 6월 27일
편집: Image Analyst 2014년 6월 27일
this is the program i used to get this figure
t1=t(1:300000);......
>> tr1=travel(1:300000,1);........
>> tr2=travel(1:300000,2);.......
>> plot(t1,tr1,t1,tr2).........
and then i write your code ... the previous figure is what i get ...
i use the plot command after the simulink run for almost 10 seconds

댓글을 달려면 로그인하십시오.


Daniel kiracofe
Daniel kiracofe 2014년 6월 28일
Well, if the time step is 0.001s and you have 300 samples, then 300 * 0.001 = 0.3, which is not 10s. So either you don't really have 0.001s time step, or you don't really have 10s of data. But if you are really sure that 300 samples = 10s, then you could just use linspace:
time = linspace(0, 10, 300); plot(time, data);
  댓글 수: 1
cmcm
cmcm 2014년 6월 28일
yes, if we calculate it, it will be 0.3 sec. ... but this is not the real time, i count the seconds when the program run and the 300 samples was almost 10 real second :(

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by