[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #54275] repelem error if a repeat instruction
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #54275] repelem error if a repeat instruction is a vector ends with 0 |
Date: |
Mon, 9 Jul 2018 08:04:31 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 |
Follow-up Comment #1, bug #54275 (project octave):
The first solution in the original submission is a little ugly.
If we didn't want to use the second solution (using "repelems"),
here is a third solution.
--- a/scripts/general/repelem.m
+++ b/scripts/general/repelem.m
@@ -299,20 +299,19 @@
else
## This works for a row or column vector.
- ## idx2 output will be a row vector.
## Get ending position for each element item.
idx_temp = cumsum (v);
- ## Row vector with enough space for output
- idx(1:idx_temp(end)) = 0;
-
## Set starting position of each element to 1.
- idx(idx_temp(1:end-1) + 1) = 1;
+ idx(idx_temp + 1) = 1;
## Set starting position of each element to 1.
idx(1) = 1;
+ ## Row vector with proper length for output
+ idx = idx(1:idx_temp(end));
+
## with prepared index
idx = (find (v != 0))(cumsum (idx));
Besides, in fact, in the subfuntion prepareIdx, the variable "idx" is actually
a row vector
except for the last line "idx = (find (v != 0))(cumsum (idx))".
The problem is that "find(v!=0)" might be a row or column vector according to
the shape of "v".
If we really wanted the output "idx" to be a row vector,
we could change that line into "idx = find (v != 0)(:).'(cumsum (idx))".
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?54275>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/