回覆列表
  • 1 # 高大美女的

    對於一個矩陣A,可以連續賦值,如

    >> A(1:3)=1:2:5

    A =

    1 3 5

    對於cell陣列,連續賦值可以用一下格式

    例1:賦以連續數字

    >> test=cell(1,3);

    >> test(1,1:3)=num2cell(1:3:9)

    test =

    [1] [4] [7]

    cell陣列中每一元素都是一個cell結構的,所以可以連續索引cell單元,賦以連續的cell結構的資料。注意不能用內容索引,即大括號{ },如test{1:3},會報錯

    >> test{1:3}=num2cell(1:3:9)

    The right hand side of this assignment has too few values to satisfy

    the left hand side.

    >> test{1:3}=1:3:9

    The right hand side of this assignment has too few values to satisfy

    the left hand side.

    例2:

    >> test(1:3)={1,"b","c"}

    test =

    [1] "b" "c"

    例3:賦以相同值

    >> test(1:3)={0}

    test =

    [0] [0] [0]

  • 中秋節和大豐收的關聯?
  • 羊肉湯燒魚能加冬瓜嗎?