Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/matlab/driver/native/conversions.rb

Instance Method Summary collapse

Instance Method Details

#to_cell_matrixObject

Flattens and converts the array to a 1 Dimensional Matlab::CellMatrix



69
70
71
72
73
74
75
76
# File 'lib/matlab/driver/native/conversions.rb', line 69

def to_cell_matrix
  cell_matrix = Matlab::CellMatrix.new(size, 1)
  
  each_with_index do |value, index|
    cell_matrix[index, 0] = value
  end
  cell_matrix
end

#to_matlabObject

Converts the array into a 1 Dimensional MATLAB numeric or cell matrix



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/matlab/driver/native/conversions.rb', line 52

def to_matlab
  if empty?
    matrix = Matlab::Matrix.new(0, 0)
    matrix.to_matlab
  elsif all? { |value| value.kind_of?(Numeric) || value.nil? }
    matrix = Matlab::Matrix.new(size, 1)
  
    each_with_index do |value, index|
      matrix[index, 0] = value
    end
    matrix.to_matlab
  else
    to_cell_matrix.to_matlab
  end
end