Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我有一个CSV文件,我想读取此文件并在每行上进行一些预先计算,以查看该行是否对我有用,如果是,我将其保存到新的CSV文件中。有人可以给我一个例子吗?更详细地讲,这就是我的数据的样子:(string,float,float)数字是坐标。
ABC,51.9358183333333,4.183255 ABC,51.9353866666667,4.1841 ABC,51.9351716666667,4.184565 ABC,51.9343083333333,4.186425 ABC,51.9343083333333,4.186425 ABC,51.9340916666667,4.18688333333333 基本上我想将具有大于50或50的距离的行保存在新文件中。字符串字段也应该被复制。谢谢 回答: 您实际上可以使用xlsread来完成此操作。在将上面的样本数据首先放置在文件'input_file.csv' ,下面是一个示例,说明如何从xlsread的三个输出中获取文件中的数值,文本值和原始数据: >> [numData,textData,rawData] = xlsread('input_file.csv') numData = % An array of the numeric values from the file 51.9358 4.1833 51.9354 4.1841 51.9352 4.1846 51.9343 4.1864 51.9343 4.1864 51.9341 4.1869 textData = % A cell array of strings for the text values from the file 'ABC' 'ABC' 'ABC' 'ABC' 'ABC' 'ABC' rawData = % All the data from the file (numeric and text) in a cell array 'ABC' [51.9358] [4.1833] 'ABC' [51.9354] [4.1841] 'ABC' [51.9352] [4.1846] 'ABC' [51.9343] [4.1864] 'ABC' [51.9343] [4.1864] 'ABC' [51.9341] [4.1869] 然后,您可以对数字数据执行所需的任何处理,然后使用xlswrite将数据行的子集重新保存到新文件中。这是一个例子: index = sqrt(sum(numData.^2,2)) >= 50; % Find the rows where the point is % at a distance of 50 or greater % from the origin xlswrite('output_file.csv',rawData(index,:)); % Write those rows to a new file 更多&回答... |
![]() |
![]() |