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

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

[Octave-bug-tracker] [bug #65877] struct field assignment using {:} prod


From: Sonu0305
Subject: [Octave-bug-tracker] [bug #65877] struct field assignment using {:} produces invalid dimension error
Date: Fri, 17 Jan 2025 07:57:34 -0500 (EST)

Follow-up Comment #3, bug #65877 (group octave):

I agree that the issue arises because Octave performs a dimension inquiry on a
non-existent value, whereas MATLAB implicitly creates the struct and field
during assignment.

octave:1> A.a = {1};
octave:2> A
A =

  scalar structure containing the fields:

    a =
    {
      [1,1] = 1
    }


octave:3> value = A.a{1};
octave:4> value
value = 1

This approach provided by you is indeed clearer and achieves the desired
result.

Also, for advance cases we can use the *subassgn* function:

octave:5> A = struct();
octave:6> A = subsasgn(A, substruct('.', 'a', '{}', {1}), 1);
octave:7> A
A =

  scalar structure containing the fields:

    a =
    {
      [1,1] = 1
    }


octave:8> value = A.a{1};
octave:9> value
value = 1

This approach also helps us achieve the desired result.

Thank You,
Swayam (Sonu0305)


    _______________________________________________________

Reply to this item at:

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

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

Attachment: signature.asc
Description: PGP signature


reply via email to

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