フィルターのクリア

Plotting values with start time and timestep

31 ビュー (過去 30 日間)
asotop
asotop 2017 年 2 月 20 日
コメント済み: dpb 2017 年 2 月 21 日
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
Frank Macias-Escriva 2017 年 2 月 20 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by