来自列的值的平均值/跳过行(textscan) [英] Average of values from a column/ Skip lines (textscan)

查看:389
本文介绍了来自列的值的平均值/跳过行(textscan)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ****** text ***** ** 
(30行包含文本和*)
******文本*******

abc
abc
abc
abc
abc
abc
abc

与一个as x和b和c作为y1和y2)

如何跳过这30行textscan?

$ p $ [x y1 y2] = textscan('file_name.txt','% f%f%f',30);

更多:如何使第三列的值平均值? b $ b

解决方案

如何跳过某些行被处理?



关于跳行:




  • 如果行数始终是静态的,并且始终在文件的开头:

    传递 HeaderLines 的值为N,N代表您不希望的数字

    [x y1 y2] = textscan('file_name.txt','%f%f%f','HeaderLines' ,30 + 2);


  • 如果所有行都以相同的字符串开头



    *通过 CommentStyle ,其中 ABC 如果所有行都跳过以 * 开始,则传递'*' 到 textscan



    [x y1 y2] = textscan('file_name.txt','%f%f%f','CommentStyle','*');







如何获得某个数组的平均值?



一些数组,使用 mean

  y1_average = mean(y1); 






textscan



的平均值
$ b


  • 一个数组的平均值或平均值 - MATLAB


I have a .txt file which looks like this:

******text*******
(30 lines containing text and *)
******text*******

a b c
a b c
a b c
a b c
a b c
a b c
a b c

(I'm creating a plot with a as x and b and c as y1 and y2)

How do I skip those 30 lines with textscan? I had this but it didn't work:

[x y1 y2] = textscan('file_name.txt', '%f %f %f', 30);

And more: how to I make the average of the values of third column?

解决方案

How do I skip certain lines from being processed?

You have a few options regarding line skipping:

  • If the number of lines are always static, and always in the beginning of the file:

    Pass HeaderLines with a value of N, with N being the numbers you'd like not to process.

    [x y1 y2] = textscan ('file_name.txt', '%f %f %f', 'HeaderLines', 30 + 2);

  • If all lines start with the same character string

    *Pass CommentStyle with a value of ABC where ABC is the comment style.

    If all lines to skip start with *, pass '*' to textscan.

    [x y1 y2] = textscan ('file_name.txt', '%f %f %f', 'CommentStyle', '*');


How do I get the average of some array?

To get the average of some array, use mean:

y1_average = mean (y1);


Documentation of textscan:

Documentation of mean

这篇关于来自列的值的平均值/跳过行(textscan)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆