필터 지우기
필터 지우기

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by