Plotting values with start time and timestep

55 次查看(过去 30 天)
Hello,
I've been delivered a set of values formatted like this:
I want to plot the graph for material 1, as function of the start time and the time step.
Please consider the following code:
filename = 'Material_Characterisation.xlsx';
num = xlsread(filename);
Test = [0:2*10^(-9):2*10^(-4)].';
plot(Test,var); grid on;
Where I've managed to isolate the values i need for material 1 as variable var, which is a 100001x1 matrix.
The problem is that the start time is 3.16*10^(-5) and I want to plot the graph for each time step.
Any help is greatly appreciated.
Regards
Andreas
  1 个评论
asotop
asotop 2017-2-20
T = zeros(100001,1);
for i=1:100001
T(i,:)=3.16*10^(-5)+2*10^(-9)*i;
end
I've tried a different approach which seem to work, but is there a simpler solution?

请先登录,再进行评论。

采纳的回答

Frank Macias-Escriva
Based on the code you have, the simplest way is:
startTime = num(1,2);
timeStep = num(2,2);
dataSize = numel(var);
t = (0:dataSize-1)*timeStep + startTime;
plot(t, var);

更多回答(3 个)

Jan
Jan 2017-2-20
编辑:Jan 2017-2-20
According to your code:
T = 3.16e-5 + 2e-9 * (1:100001);
But if the start time is 3.16e-5, you need:
T = 3.16e-5 + 2e-9 * (0:100000);
  2 个评论
Jan
Jan 2017-2-21
@dpb: I've cleaned up the comments already. Independent from the question, if I made a mistake or not: Thanks for checking the details of my submissions. This is helpful and improves the quality of the forum. Actually I thought this kind of mutual assistence is welcome for anybody, but there are exceptions.
dpb
dpb 2017-2-21
Ok thnx for cleaning up my mess, Jan...:) It's always interesting to see if others have same or a novel idea so I read most other answers to those I either answer or ponder over and don't for some reason think have a good solution....here, I just thought the number of points was 100000, simply misread it. Type is smaller these days than it used to be... :)

请先登录,再进行评论。


dpb
dpb 2017-2-20
t0=3.15E-5; % origin
dt=2E-9; % timestep
N=length(var); % number observations
t=[t0:dt:t0+(N-1)*dt].'; % time vector corresponding (N-1 dt intervals)
There's a new timeseries class that should be ideal for such things but its implementation leaves something to be desired. Ideally one could create the series by setting the properties of
ts.TimeInfo.Start=t0;
ts.TimeInfo.Increment=t0;
ts.TimeInfo.Length=length(var);
and it would populate it automgically. But, unfortunately, TMW has at least to date made the Length read only so afaict the only way to generate the time series itself is to still do the above vector generation manually. Seems a waste of effort and unnecessary neutering of what could be helpful class... :(

asotop
asotop 2017-2-21
Thanks everyone. It cleared up my question.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by