How to output a value of an array for a specific value of time?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Abhinav Prashant Mohanakrishnan
am 18 Sep. 2014
Kommentiert: David Sanchez
am 18 Sep. 2014
I have the following section of code. I am generating arrays of t and v to create a plot.
wn and theta are given.
n=3; N=500; t=linspace(0,n*Tn,N); v=rho*cos(wn*t+theta);
Now how do I print the value of v for t=1?
0 Kommentare
Antworten (1)
David Sanchez
am 18 Sep. 2014
idx = find(t==1);
v(idx)
or in a single line:
v( find(t==1) )
5 Kommentare
Abhinav Prashant Mohanakrishnan
am 18 Sep. 2014
Bearbeitet: Abhinav Prashant Mohanakrishnan
am 18 Sep. 2014
David Sanchez
am 18 Sep. 2014
Absolutely, as explained by Daniel in http://www.mathworks.com/matlabcentral/answers/48942-insert-element-in-vector you can do this:
t=linspace(0,n*Tn,N);
idx = find(t<1,1);
insert = @(a, x, n)cat(2, x(1:n), a, x(n+1:end)); % function to insert the value "a" in array "x" in position "n"
t = insert(1, t, idx); % now t contains the value "1"
v=rho*cos(wn*t+theta);
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!