How can I get the first two non-zero values of a timeseries vector?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I'd like to get the first two non-zero values of a timeseries vector and afterwards divide the first through the second value.
I tried to find the non-zero values with a find-block in combination with a selector block. I connected the output of the find-block to Idx of the selector-block and the original vector to U. But the find-block outputs all indices, also of the values which are zero. This is the error: "Element 1 of input port Idx1 in 'DC_Kopplung_1/Battery and DCDC-converter bidirectional/Selector' has a value of 0. This value is not within the range of permissible values (1 through 1) that allows selection of a valid input data element"
Maybe someone has a better solution?
Thanks, Nina
0 Kommentare
Antworten (1)
Robert
am 29 Mär. 2016
By default, the Find block uses zero-based-indexing (first index is 0), but the Selector block uses one-based-indexing (first index is 1). You can tell the Find block to use one-based-indexing in its dialog parameters so that the two agree. Then you should add a selector block between the output of Find and your existing selector block that will grab the first and second elements of the output of Find so that you get these two indices rather than the indices of all non-zero values.
Otherwise your method is sound as far as I can tell. Use the first and second indices returned by Find (using one-based-indexing) to grab the first and second non-zero elements from your input to Find and compute their quotient.
0 Kommentare
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!