필터 지우기
필터 지우기

How do i add a time vector to a existing table?

조회 수: 3 (최근 30일)
Wouter
Wouter 2022년 12월 21일
댓글: Wouter 2022년 12월 21일
I have a set of given data but they do not include a time. I am trying to add a time (Tijd) vector but if i add a time vector, i get the messages that vectors must be the same length.
The data is a set amount of measurements (4001) but with a sample rate of 50Hz. I ofcourse want the time to be in seconds. So I thought I would make the steps in the graph steps of 81 because 4001/50 ≈ 81. But even without the steps it still gives me the error of vectors must be the same length.
Any and all help is appreciated!
clear all
close all
clc
load('ACE2-opdracht-2-persoonlijk.mat', 'meetdata');
A = meetdata;
Motortoerental = A (:,1);
Stuurspanning = A (:,2);
Tijd = 1:81:4001;
figure;
subplot(1,2,1)
plot(Tijd, Motortoerental); hold on
xlabel('Tijd(s)')
ylabel('Toerental(Omw/min)')
grid;
subplot(1,2,2)
plot(Tijd, Stuurspanning); hold on
xlabel('Tijd(s)')
ylabel('Stuurspanning(V)')
grid;
  댓글 수: 2
Stephen23
Stephen23 2022년 12월 21일
Avoiding the possibility of floating point issues with the last value:
(0:4000)./50
ans = 1×4001
0 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.2000 0.2200 0.2400 0.2600 0.2800 0.3000 0.3200 0.3400 0.3600 0.3800 0.4000 0.4200 0.4400 0.4600 0.4800 0.5000 0.5200 0.5400 0.5600 0.5800
Wouter
Wouter 2022년 12월 21일
This also works! Why would i do it this way?

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2022년 12월 21일
Shouldn't it be
Tijd = (0:0.02:4000*0.02).'
?
  댓글 수: 3
Torsten
Torsten 2022년 12월 21일
Your vector Tijd must have 4001 elements in order to plot Tijd against the other two arrays Motortoerental and Stuurspanning.
You said the measurements are every 0.02 s - thus
Tijd = (0:0.02:4000*0.02).'
Wouter
Wouter 2022년 12월 21일
Oh now i understand. Thanks for the help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by