- loop over the length of the data vector.
- detect any discontinuities (e.g. difference/offset, or some other metric).
- shift the remaining data by the detected offset (use indexing).
Formatting data using an if function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Benedikt Wessel
le 21 Sep 2018
Commenté : Benedikt Wessel
le 22 Sep 2018
Hello everybody, how can I adjust the data, so that the purple curve will always be connected? The next purple section should start at the end of the section before.... I've no clue how to do that. I really need help, because of this thing I'm not able to finish my bachelor thesis. Thanks guys.
(Ignore the legend)
C=cumsum(diffE,'omitnan'); % needed Capacity
Cbmax= 1000; % in MWH, max. capacity of the battery storage
Cbmin= 100; % in MWh, deep charge border
imax= C>=Cbmax-Cbmin; % find where C is larger than the Capacity
imin= C<=0; % find where C is =0
C(imax) = Cbmax-Cbmin; % if C is larger than Cbmax: C=Cbmax
C(imin) = Cbmin-Cbmin; % if C is smaller than Cbmin: C=Cbmin
Cres=cumsum(diffE,'omitnan');
for k=1:length(Cres)-1
if Cres(k)>(Cbmax-Cbmin) && Cres(k)>Cres(k+1)
C(k+1)=C(k)-Cres(k)+Cres(k+1);
end
if Cres(k)>(Cbmax-Cbmin) && C(k)<(Cbmax-Cbmin)
C(k+1)=C(k)-Cres(k)+Cres(k+1);
end
end
0 commentaires
Réponse acceptée
Stephen23
le 21 Sep 2018
Modifié(e) : Stephen23
le 22 Sep 2018
"how can I adjust the data, so that the purple curve will always be connected?"
Something like this:
for k = 2:numel(vec)
d = diff(vec(k-1:k))
if abs(d)>tol % pick a tolerance, or some metric
vec(k:end) = vec(k:end)-d;
end
end
I just tried this on a fake data vector:
tol = 2;
vec = [0,1,2,3,4,10,11,12,13];
giving:
>> vec
vec =
0 1 2 3 4 4 5 6 7
You could fine-tune the algorithm so that it includes an offset of the same sign as d, but with magnitude tol. Also it would pay to do some reading into detecting discontinuities:
3 commentaires
Stephen23
le 22 Sep 2018
Modifié(e) : Stephen23
le 22 Sep 2018
"But unfortunately the diff functions is always in an endless loop"
Check if you have any other functions named diff:
which diff -all
And if so, rename them. Also ensure that you do not have any variables name diff. Note that diff is not strictly required, you could do this:
d = vec(k)-vec(k-1)
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!