簡體   English   中英

結構中的八度結構

[英]Octave structure within a structure

我想在 Octave 的結構中創建一個結構。 看起來像

class =
    {
        grade = Graduate
        studentname = John
        university =  St. Jones
        student=
             {
                 name=John
                 age=18
                 address=Houston
             }

   } 

為了在一個結構中實現這個結構,我寫下了

>> class.grade='graduate';
>> class.studentname='John';
>> class.university='St.Jones';

>> student.name='John';
>> student.age=18;
>> student.address='Houston';

>>student.class=struct %To create structure within a structure

我得到了這個 output:

student =

scalar structure containing the fields:

name = John
age =  18
address = Houstan
class =

  scalar structure containing the fields:

我不明白為什么 class 結構在這里是空的? 如果我嘗試像那樣運行此代碼也是如此

>> class.student=struct

output 是

class =

  scalar structure containing the fields:

grade = graduate
studentname = John
university = St.Jones
student =

  scalar structure containing the fields:

請幫我解決我的問題。

所以,在我看來,有兩種可能。

要么設置你的(子)結構student ,然后設置class.student = student 這樣, class中的現場student就被隱式地制成了一個(子)結構。 代碼將是這樣的:

class.grade = 'graduate';
class.studentname = 'John';
class.university = 'St.Jones';

student.name = 'John';
student.age = 18;
student.address = 'Houston';

class.student = student

        class =

          scalar structure containing the fields:

            grade = graduate
            studentname = John
            university = St.Jones
            student =

              scalar structure containing the fields:

                name = John
                age =  18
                address = Houston

或者你可以在一開始就使用嵌套結構,如下所示:

class.grade = 'graduate';
class.studentname = 'John';
class.university = 'St.Jones';

class.student.name = 'John';
class.student.age = 18;
class.student.address = 'Houston';

class

        class =

          scalar structure containing the fields:

            grade = graduate
            studentname = John
            university = St.Jones
            student =

              scalar structure containing the fields:

                name = John
                age =  18
                address = Houston

同樣, class中的現場student也隱含地制作了一個(子)結構。

希望有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM