MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER Manual do Utilizador Página 215

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 408
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 214
Working with Java Arrays
5-45
java.lang.Double[][]:
[11] [12] [13] [14]
[21] [22] [23] [24]
[ 0] [ 0] [ 0] [ 0]
Creating a Copy of a Java Array
You can create an entirely new array from an existing Java array by indexing
into the array to describe a block of elements, (or subarray), and assigning this
subarray to a variable. The assignment copies the values in the original array
to the corresponding cells of the new array.
As with the example in section “Creating a New Array Reference” on page 5-44,
an original array is created and initialized. But, this time, a copy is made of the
array contents rather than copying the array reference. Changes made using
the reference to the new array do not affect the original.
origArray = javaArray('java.lang.Double', 3, 4);
for m = 1:3
for n = 1:4
origArray(m,n) = java.lang.Double((m * 10) + n);
end
end
origArray
origArray =
java.lang.Double[][]:
[11] [12] [13] [14]
[21] [22] [23] [24]
[31] [32] [33] [34]
% ----- Make a copy of the array contents -----
newArray = origArray(:,:);
newArray(3,:) = java.lang.Double(0);
origArray
origArray =
java.lang.Double[][]:
[11] [12] [13] [14]
[21] [22] [23] [24]
[31] [32] [33] [34]
Vista de página 214
1 2 ... 210 211 212 213 214 215 216 217 218 219 220 ... 407 408

Comentários a estes Manuais

Sem comentários