Assignment through repeated indexing on LHS

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Assignment through repeated indexing on LHS

Philip Nienhuis
(Couldn't find it in the manual or on the web)
I wonder if the following is a legal construct:

cell_array(:, 3:5)(index-vector) = some_value

or with a real example (invoking the testc cell array in  attached testc.mat
<http://octave.1599824.n4.nabble.com/file/t131602/testc.mat>  ) I tried:

load testc.mat
idx = find (cellfun (@isempty, testc(:, 3:8)));
testc(:, 3:8)(idx) = NaN

...yielding the following somewhat incomprehensible (to me) error message:
error: () must be followed by . or close the index chain

Am I correct to conclude that repeated indexing on the LHS of an expression
is illegal, or at least unsupported?
In that case I think the error message could be more clear, like explicitly
mentioning that repeated indexing on LHS is not permitted.

Typing:
testc(:, 3:8)(idx)
works fine of course as it is essentially a RHS expression.

Thanks,

Philip



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html

Reply | Threaded
Open this post in threaded view
|

Re: Assignment through repeated indexing on LHS

Avinoam
Philip Nienhuis wrote

> (Couldn't find it in the manual or on the web)
> I wonder if the following is a legal construct:
>
> cell_array(:, 3:5)(index-vector) = some_value
>
> or with a real example (invoking the testc cell array in  attached
> testc.mat
> &lt;http://octave.1599824.n4.nabble.com/file/t131602/testc.mat&gt;  ) I
> tried:
>
> load testc.mat
> idx = find (cellfun (@isempty, testc(:, 3:8)));
> testc(:, 3:8)(idx) = NaN
>
> ...yielding the following somewhat incomprehensible (to me) error message:
> error: () must be followed by . or close the index chain
>
> Am I correct to conclude that repeated indexing on the LHS of an
> expression
> is illegal, or at least unsupported?
> In that case I think the error message could be more clear, like
> explicitly
> mentioning that repeated indexing on LHS is not permitted.
>
> Typing:
> testc(:, 3:8)(idx)
> works fine of course as it is essentially a RHS expression.
>
> Thanks,
>
> Philip
>
>
>
> --
> Sent from:
> http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html


testc (find (cellfun (@isempty, testc))) = {NaN}

also works, though it's not exactly what you want.

Avinoam



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html