help-octave
[Top][All Lists]

## Re: problem plotting "N-d object"

 From: Sergei Steshenko Subject: Re: problem plotting "N-d object" Date: Fri, 17 Feb 2012 08:24:26 -0800 (PST)

```

----- Original Message -----
> Sent: Friday, February 17, 2012 6:06 PM
> Subject: Re: problem plotting "N-d object"
>
> On Feb 17, 2012, at 10:15 AM, Sergei Steshenko wrote:
>
>>  Hello,
>>
>>  here is a screen session:
>>
>>  "
>>  octave:3> foo(1,1,:) = [1 2 3]
>>  foo =
>>
>>  ans(:,:,1) =  1
>>  ans(:,:,2) =  2
>>  ans(:,:,3) =  3
>>
>>  octave:4> plot(foo(1,1,:));
>>  error: transpose not defined for N-d objects
>>  error: called from:
>>  error:
> /home/qemu/AFSWD/20111122/octave-3.4.2/share/octave/3.4.2/m/plot/private/__plt__.m
>
> at line 179, column 8
>>  error:
> /home/qemu/AFSWD/20111122/octave-3.4.2/share/octave/3.4.2/m/plot/private/__plt__.m
>
> at line 104, column 17
>>  error:
> /home/qemu/AFSWD/20111122/octave-3.4.2/share/octave/3.4.2/m/plot/plot.m at
> line
> 194, column 9
>>  octave:4> plot(foo(1,1,:)(:));
>>  octave:5>
>>
>>  ".
>>
>>  I don't understand why 'octave' complains about N-d objects -
> to me "foo(1,1,:)" looks like a 1-d object. Because the first two of
> the three indexes are fixed in the expression.
>>
>>
>>  And adding "(:)" solves the problem.
>>
>>  Just wondering - should it be that hard for end user ? Does Matlab behave
> the sane way ?
>>
>>  Thanks,
>>    Sergei.
>
> For either plot(foo) or plot(foo(1,1,:), Matlab gives ...
>
>     plot (foo)
>     Error using plot
>     Data may not have more than 2 dimensions
>
> Even so, maybe an appropriate solution is to check if the numberic inputs
> have
> ndim > 2 and attempt to apply squeeze before throwing an error ?
>
> If you like this idea, please open a feature request in the tracker.
>
>     https://savannah.gnu.org/bugs/?group=octave
>
> Ben

First of all, I still don't understand why both Matlab/Octave consider the data
to have more than 2 dimensions - this is because in my 3-d object two indexes
are _fixed_, they are _constants_.

Because of my math background I find it senseless to say that a 3-d cube
projection onto a 2-d plane is still 3-d - it is just 2-d, and, likewise, that
2-d cube image of a cube on a plane being projected onto a 1-d straight line
would be just 1-d.

...

You know what, I dare to extend the subject/issue.

IMO in Octave/Matlab world the difference between line and column vectors is a
nuisance in many many cases, and I mention vectors because of "transpose not
defined" (specifically, "transpose") in the original error message.

I think Octave should automatically apply '(:)' operation whenever row/column
trait doesn't matter. And probably the 'plot' family of functions is a good
place to begin with applying this - as you wrote "maybe an appropriate solution
is to check if the numberic inputs have ndim > 2 and attempt to apply squeeze
before throwing an error".

Thanks,
Sergei.

>

```