在R语言中,如果我们有一个向量和一个索引列表,我们可以使用负数索引来表示“除这些索引之外的所有元素”的概念。特别地,考虑以下R代码:
data = rnorm(100)
indices = sample(1:length(data), length(data)/2)
training_data = data[indices]
test_data = data[-indices]
在这段代码之后,sampled_data
包含了所有在 data
中索引不包含在 indices
中的元素。在Matlab中是否有相应的功能?
我尝试直接使用相同的语法(当然是使用 ()
代替 []
),但是它只是报错了。
Subscript indices must either be real positive integers or logicals.