switching functions for continuous time
Mostra commenti meno recenti
I am plotting a function for say:
t = 0:0.1:1 %seconds
I want to use one function for:
t < 0.2
One for:
t >= 0.2 & t <= 0.0.8
And then one for:
t >0.8
I can't get it to work using the conventions I have stated aboce
Risposta accettata
Più risposte (8)
A
il 6 Giu 2011
0 voti
3 Commenti
Walter Roberson
il 6 Giu 2011
Yes, just replace f1, f2, f3 with your functions. The above code already pieces the parts together.
A
il 7 Giu 2011
Walter Roberson
il 7 Giu 2011
plot(t,y)
A
il 14 Giu 2011
0 voti
2 Commenti
Walter Roberson
il 14 Giu 2011
"for" loop and an if/elseif structure if it is expensive to compute the values.
If computing the values is relatively cheap,
y = f1(x);
idx = find(y >= 80,1,'first');
y(idx:end) = f2(x(idx:end));
A
il 15 Giu 2011
A
il 21 Giu 2011
0 voti
5 Commenti
Walter Roberson
il 21 Giu 2011
There can be multiple x of equal weight.
ydiff = abs(y - SpecificY);
closestX = x(ydiff == min(ydiff)); %warning, can have multiple entries
You would need different logic if, for example, you wanted only x for which y did not exceed the specific Y; the above logic finds the x for which the y is numerically closest above _or_ below the specific Y.
A
il 21 Giu 2011
A
il 21 Giu 2011
A
il 21 Giu 2011
Walter Roberson
il 21 Giu 2011
Good point about the index; sorry about that.
If your y are in increasing order, then
find(SpecificY < y,1,'last')
A
il 23 Giu 2011
3 Commenti
A
il 23 Giu 2011
Walter Roberson
il 23 Giu 2011
Time_Value = V_In * .632;
Time_Check = find(V_C_SS <= Time_Value,1,'last');
Time_Constant = t(Time_Check);
A
il 23 Giu 2011
A
il 23 Giu 2011
4 Commenti
Walter Roberson
il 23 Giu 2011
You haven't really defined what it means for f1 to "end", or what it means to use the final values of f1 for the initial conditions of f2. So, guessing...
overlap = 5; %samples
y = f1(x);
idx = find(y >= 80,1,'first');
startat = max(1,idx-overlap);
f2vals = f2(x(startat:end));
y(idx:end) = f2vals(idx-startat+1:end);
A
il 23 Giu 2011
Walter Roberson
il 23 Giu 2011
That's what the code you posted above does, unless f2 is sensitive to the position of the x as well as to the value of the x. If it _is_ sensitive to the position of the x, then the next thing we would need to know is whether the f2 values are calculated independently or if values from earlier input influence later output.
If there is dependence on the position then,
y = f1(x);
y2 = f2(x);
idx = find(y >= 80,1,'first');
y(idx:end) = y2(idx:end);
A
il 23 Giu 2011
A
il 23 Giu 2011
1 Commento
Walter Roberson
il 23 Giu 2011
Time_Check = find(V_C_SS > Time_Value,1,'first') - 1;
Provided that your values do not start out above the time constant, dip, rise, with it being the point on the rise you want to get.
A
il 23 Giu 2011
0 voti
A
il 24 Giu 2011
0 voti
Categorie
Scopri di più su Annotations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!