trying to plot acceleration to time

8 Ansichten (letzte 30 Tage)
omar
omar am 9 Jun. 2023
Kommentiert: omar am 9 Jun. 2023
%i am a bignner in matlab and i have to plot a acceleration to time plot but it appears to me as a dot can anyone tell me what i am doing wrong
%here is the code
r=2500;%ft
vo=60;%mi/h
t=8;%sec
vf=45;%mi/h
vf2=mphtofts(vf);%mi/h to ft/sec
vo2=mphtofts(vo);%mi/h to ft/sec
at=(vf2-vo2)/t
an=vo2^2/r
a=sqrt(at^2+an^2)
theata = atand(an/at);
theata=abs(theata)
plot(t,a,'*')
note:i want to plot a,at,an with relation to time but i cant even make a single one work
  2 Kommentare
Dyuman Joshi
Dyuman Joshi am 9 Jun. 2023
"i have to plot a acceleration to time plot but it appears to me as a dot can anyone tell me what i am doing wrong"
You get a dot because you only have 1 pair to plot. You will need more than 1 pair for plotting to obtain a curve.
If you have a theoretical relation between the variables, you can consider using fplot
Santiago Díaz Riofrío
Santiago Díaz Riofrío am 9 Jun. 2023
If you want to plot multiple points you have to give variable points to matlab. As you are giving only one point of time you are going to obtain only one point of 'at', 'an' and 'a'. To solve this you have to create an array with multiple points of time, you can do it easily using the ':' operator. But you also have to store the 'at','an' and 'a' obtained values for the different points of the time in another array. You can try this code:
r=2500;%ft
vo=60;%mi/h
t=0:0.5:8;%sec This will create you an array from 0 to 8 with a step of 0.5
vf=45;%mi/h
vf2=mphtofts(vf);%mi/h to ft/sec
vo2=mphtofts(vo);%mi/h to ft/sec
at=zeros(1,length(t)); %This initialises the at array with the length of the array of t
an=zeros(1,length(t));
a=zeros(1,length(t));
for i=1:length(t)
at(i)=(vf2-vo2)/t(i)
an(i)=vo2^2/r
a(i)=sqrt(at(i)^2+an(i)^2)
end
theata = atand(an(end)/at(end));
theata=abs(theata)
figure()
plot(t,a,'*')
figure()
plot(t,at,'*')
figure()
plot(t,an,'*')
Notice that 'an' is not function of time so if you plot it against time you will obtain a straight line of the same value. the 'theata' variable I suposed that you only need the values for t=8 that is why you take the last values of the respective arrays of 'at' and 'an'. I suggest that next time you explain the problem a little more in depth, such as what the variables refer to and so on, so that we can help you better and understand what you are looking for. I hope this is helpful.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Tushar
Tushar am 9 Jun. 2023
Bearbeitet: Tushar am 9 Jun. 2023
Hello Omar,
The reason you are getting a single dot is that your variables 't' and 'a' are not any vectors . Instead they are singular values. If you want a proper plot of acceleration against time you must use time vector as the first argument and the correspnding accelerration vector as the second argument for plot() function.
Also as you mentioned you are a beginner in MATLAB, please refer this document for indepth understanding of all the variations for plotting of 2-D data available in MATLAB. Link

Kategorien

Mehr zu Performance and Memory finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by