Filter löschen
Filter löschen

Plotting values with start time and timestep

31 Ansichten (letzte 30 Tage)
asotop
asotop am 20 Feb. 2017
Kommentiert: dpb am 21 Feb. 2017
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 Kommentar
asotop
asotop am 20 Feb. 2017
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Frank Macias-Escriva
Frank Macias-Escriva am 20 Feb. 2017
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);

Weitere Antworten (3)

Jan
Jan am 20 Feb. 2017
Bearbeitet: Jan am 20 Feb. 2017
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 Kommentare
Jan
Jan am 21 Feb. 2017
@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 am 21 Feb. 2017
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... :)

Melden Sie sich an, um zu kommentieren.


dpb
dpb am 20 Feb. 2017
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 am 21 Feb. 2017
Thanks everyone. It cleared up my question.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by