octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #65553] stream2 doesn't extend matrices like m


From: Andy Adler
Subject: [Octave-bug-tracker] [bug #65553] stream2 doesn't extend matrices like matlab
Date: Wed, 3 Apr 2024 09:16:27 -0400 (EDT)

URL:
  <https://savannah.gnu.org/bugs/?65553>

                 Summary: stream2 doesn't extend matrices like matlab
                   Group: GNU Octave
               Submitter: andy_adler
               Submitted: Wed 03 Apr 2024 01:16:27 PM UTC
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: Andy Adler
        Originator Email: 
             Open/Closed: Open
                 Release: 9.1.0
         Discussion Lock: Any
        Operating System: Any
           Fixed Release: None
         Planned Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Wed 03 Apr 2024 01:16:27 PM UTC By: Andy Adler <andy_adler>
Sorry for the stream of reports. I'm working on a release of eidors.org and
I'm testing matlab/octave compatibility.

In matlab, the following code works. In octave, the
issue is the error below:
----
xp = linspace(-2,2,200); yp = linspace(-3,3,150);
sx = linspace(-1,1,20); sy = linspace(-1,1,20);
[xc,yc]= meshgrid(xp,yp);
streamline(xp,yp,xc,yc,sx,sy)
% error: stream2: matrix dimensions must match
----

This can be corrected with a function "fix_to_matrix" in the following patch:

share/octave/9.1.0/m/plot/draw$ diff -c stream2.m stream2-old.m 
*** 92,103 ****
        [x, y] = meshgrid (1:n, 1:m);
      case 6
        [x, y, u, v, spx, spy] = varargin{:};
+       [x, u] = fix_to_matrix(x, u, 1);
+       [y, v] = fix_to_matrix(y, v, 2);
      case 7
        [x, y, u, v, spx, spy, options] = varargin{:};
+       [x, u] = fix_to_matrix(x, u, 1);
+       [y, v] = fix_to_matrix(y, v, 2);
      otherwise
        print_usage ();
    endswitch
--- 92,99 ----
***************
*** 187,223 ****
  
  endfunction
  
+ # check if x is vector. Make full size
+ # axis (=1 for x and =2 for y)
+ function [x, u] = fix_to_matrix(x, u, axis);
+   if size_equal(x,u)
+     return
+   endif
+   if all(size(x)>1)
+     return
+   endif
+    
+   dirn = diff( x );
+   if all(dirn>0)
+     doflip = false;
+   elseif all(dirn<0)
+     doflip = true;
+   else
+     error ("stream2: axis not monotonic");
+   end
+   
+   # extend x in the rows
+   x = x(:).';
+   x = x(ones(size(u,axis),1),:);
+   if axis==2
+     x = x.';
+   endif
+ 
+   if doflip % flipud if axis=2, rl if axis=1
+     x = flip( x, 3-axis );
+     u = flip( u, 3-axis );
+   endif
+ endfunction
  
  %!demo
  %! clf;
--- 183,188 ----








    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?65553>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]