how to plot with respect to time insted of samples
15 次查看(过去 30 天)
显示 更早的评论
hello,
i have sensor which gives voltage output based on change in radiant temperature, the plot i am doing now is voltage signal in y axis and samples per trigger in x axis,
i want it to change the x axis to time.
plz anyone help.
2 个评论
Walter Roberson
2013-1-7
How are you plotting against samples per trigger? That is normally a fixed quantity. Are you experimenting with changing the number of samples you gather at one time ?
回答(2 个)
Lalit Patil
2013-1-7
编辑:Lalit Patil
2013-1-7
% Assign figure(1) to your V against samples program.. Then
figure(2)
V = your data
T = 1:100 % specify time unit
plot(T,V)
0 个评论
Walter Roberson
2013-1-15
Ah, your current x axis is not samples per trigger: it is sample number within the buffer.
So change your code to keep track of the number of times you have previously sampled. Then if you know your sampling frequency FS in Hz, use
Previous_Triggers = 0; %before loop
%in loop
t = (Previous_Triggers * Samples_Per_Trigger + (0:Samples_Per_Trigger-1)) ./ FS;
plot(t, V);
Previous_Triggers = Previous_Triggers + 1;
3 个评论
Walter Roberson
2022-3-3
When practical it is typically best to allocate a fixed-sized buffer, and to write new samples into it by indexing (and then increase the variable that indicates where to write to next.)
When you write into a fixed-sized buffer, then you have the advantage that you never need to spend time expanding the buffer as new data comes in -- which can be a fairly expensive operation of not coded correctly.
There are alternatives. For example in some cases you only need to retain a certain number of samples. The most efficient way to do that typically involves using a "circular buffer"
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!