help-octave
[Top][All Lists]
Advanced

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

Re: next problem


From: Rich Drewes
Subject: Re: next problem
Date: Mon, 22 Dec 2003 19:37:18 -0800 (PST)

On Mon, 22 Dec 2003, Przemek Klosowski wrote:

> Can anyone explain to me why do I need the transpose, i.e. why, in
> Matlab, y(:,:,:,:)=[x, x, x, x] and y=[x, x, x, x] are different?

I oversimplified my example problem.  The real line I was having trouble
converting from Matlab looked more like this:

octave:3> F=[1,2,3; 4,5,6; 7,8,9]
octave:4> g(:,:,1,1)=F
error: invalid number of indices (4) for indexed assignment
error: assignment failed, or no method for `<unknown type> = matrix'
error: evaluating assignment expression near line 4, column 11

The problem seems to be that Octave can't deal with (for example)
assigning 2 dimensions of a 4 dimensional array.  Matlab can, and of
course this idiom is all over the program I am trying to port.  Can you
suggest a convenient way of dealing with the issue of assigning certain
dimensions of a higher-dimensional array?  I can see elaborate ways of
working around this, but a conveniently similar idiom would make porting
much easier.

>     dff=d;
>     i=find(d>pi);
>     dff(i)=2*pi-d(i);
> 
> Simplify, simplify: 
> 
>     dff=d;
>     i = d>pi ;
>     dff(i)=2*pi-d(i);

This is a great solution, thanks, even better than Geraint's!

Rich 




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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