matlab中如何将循环数据一项一项保存到excel文件中
我在 Excel 文件工作表 1 中有大量数据。列数是固定的 (6),但有很多行。
对于每 3 行,我需要选出第二列的最小值并将整行保存到 Excel 文件或工作表 2 中,我将如何编写脚本?
item.xls(sheet 1):
0.3 0.5 0.1 0.8 0.4 0.6
0.2 0.4 0.9 0.1 0.9 0.4
0.2 0.3 0.1 0.01 0.2 0.5
0.3 0.5 0.1 0.8 0.01 0.2
0.2 0.2 0.9 0.1 0.2 0.4
0.2 0.3 0.1 0.01 0.3 0.5
.......
前3行中,第2列的最小值为0.3,然后将整行写入Excel文件的sheet 2中。
然后接下来的3行,第2列的最小值是0.2,然后将整行写入Excel文件的第2张表中。
我想得到的结果是:
item.xls (sheet2):
0.2 0.3 0.1 0.01 % 1st 3 rows, the minimum value is 0.3 in 2nd column
0.2 0.2 0.9 0.1 % 2nd set of 3 rows, the minimum value is 0.2 in 2nd column
...
I have a huge set of data in Excel file sheet 1. The number of columns is fixed (6) but there are lots of rows.
For every 3 rows, I need to pick out the minimum value of 2nd column and save the whole row into Excel file or sheet 2, how am I going to write the script?
item.xls (sheet 1):
0.3 0.5 0.1 0.8 0.4 0.6
0.2 0.4 0.9 0.1 0.9 0.4
0.2 0.3 0.1 0.01 0.2 0.5
0.3 0.5 0.1 0.8 0.01 0.2
0.2 0.2 0.9 0.1 0.2 0.4
0.2 0.3 0.1 0.01 0.3 0.5
.......
In the first 3 rows, the minimum value of 2nd column is 0.3, then write the whole row into sheet 2 of the Excel file.
Then the next 3 rows, the minimum value of 2nd column is 0.2, then write the whole row into sheet 2 of the Excel file.
The result I would like to get is:
item.xls (sheet2):
0.2 0.3 0.1 0.01 % 1st 3 rows, the minimum value is 0.3 in 2nd column
0.2 0.2 0.9 0.1 % 2nd set of 3 rows, the minimum value is 0.2 in 2nd column
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面,对您的问题进行一些澄清将有助于找到更好的解决方案。根据我对你的问题的解释,以下内容可能会有所帮助。我在这里生成随机测试数据。
尝试一下,如果它不完全是您想要的,请发表评论以澄清您的问题。
Down, some clarification on your problem would help to find a better solution. Based on my interpretation of your question, the following bit may help. I'm generating random test data here.
Try this out and if it's not quite what you are looking for, post a comment to clarify your question.
我将展示如何以矢量化方式从数据中提取相关行。我将把读取/写入 Excel 文件的部分留给你(它应该很简单):
I will show how to extract the relevant rows from the data in a vectorized manner. I will leave the part of reading/writing excel files to you (it should be straightforward):