make vectors same length using min function
Mostra commenti meno recenti
dear community let me ask your support.
my data:
x = [2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016];
y = [0, 0.05, 0.1, 0.15, 0.2];
a = [2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,2018,2019];
b = [0, 0.05, 0.1, 0.15, 0.2, 0.4];
I'm trying to make x & a vector lenght same as y & b vector length so Im using min fucntion
minlen = min(length(y), length(x));
minlen = min(length(b), length(a));
I'm trying to get x & a vector updated instead of getting this ans
x(1:minlen);

how can I make x & a equal to ans respectively? like this:
x = [2008, 2009, 2010, 2011, 2012];
a = [2008, 2009, 2010, 2011, 2012, 2013];
any feedback will be highly appreciated
Risposta accettata
Più risposte (1)
x = [2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016];
y = [0, 0.05, 0.1, 0.15, 0.2];
a = [2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,2018,2019];
b = [0, 0.05, 0.1, 0.15, 0.2, 0.4];
minlen = min(length(y), length(x));
You could use indexing and assignment:
xbackup = x; % for use in the next block of code
x = x(1:minlen) % Note the added "x = " to assign the indexing result back to x
x = xbackup % restoring the original x since the previous line overwrote it
x = trimdata(x, minlen)
1 Commento
A-Rod
il 17 Giu 2024
Categorie
Scopri di più su Calendar in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!