以下代码示例展示了如何从原始数据表中读取 3 的倍数行数的数据,并将其存储到一个新的数据表中:

% 读取原始数据表
data = readtable('original_data.csv');

% 获取3的倍数行数的索引
indices = mod(1:size(data,1),3) == 0;

% 选择3的倍数行数的数据
new_data = data(indices,:);

% 将新数据表写入文件
writetable(new_data,'new_data.csv');

代码解释:

  1. 读取原始数据表: 使用 readtable 函数读取名为 'original_data.csv' 的数据表,该数据表包含需要处理的数据。
  2. 获取 3 的倍数行数的索引: 使用 mod 函数计算每一行的索引是否是 3 的倍数,得到一个布尔型向量 indices。
  3. 选择 3 的倍数行数的数据: 使用 indices 向量选择原始数据表中对应的行,得到一个新的数据表 new_data,该数据表只包含 3 的倍数行数的数据。
  4. 将新数据表写入文件: 使用 writetable 函数将新数据表 new_data 写入名为 'new_data.csv' 的文件中。

原文地址: https://www.cveoy.top/t/topic/npjL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录