Borrar filtros
Borrar filtros

Plotting values with start time and timestep

31 visualizaciones (últimos 30 días)
asotop
asotop el 20 de Feb. de 2017
Comentada: dpb el 21 de Feb. de 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 comentario
asotop
asotop el 20 de Feb. de 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?

Iniciar sesión para comentar.

Respuesta aceptada

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

Más respuestas (3)

Jan
Jan el 20 de Feb. de 2017
Editada: Jan el 20 de Feb. de 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 comentarios
Jan
Jan el 21 de Feb. de 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 el 21 de Feb. de 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... :)

Iniciar sesión para comentar.


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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by