.TXT FILES IN MATLAB

≯℡__Kan透↙ 提交于 2019-12-25 18:33:43

问题


I would like to know about loading .txt files in matlab. The vector data i have is given as a row for which i would like to calculate mean and other stats..

Kindly suggest me a way for that..

Thanks, Aishwarya


回答1:


If you have a txt file with row vector data that look like:

file.txt

3.4
-4.1
1.5
-3
...

Then you can simply use:

data = load('file.txt');   #% load file
N = length(data);          #% number of elements
mu = mean(data);           #% mean
sigma = std(data);         #% standard deviation
plot(data)                 #% simple plot



回答2:


csvread

Given the file csvlist.dat that contains the comma-separated values

 02, 04, 06, 08, 10, 12
   03, 06, 09, 12, 15, 18
   05, 10, 15, 20, 25, 30
   07, 14, 21, 28, 35, 42
   11, 22, 33, 44, 55, 66

To read the entire file, use

csvread('csvlist.dat')

ans =

     2     4     6     8    10    12
     3     6     9    12    15    18
     5    10    15    20    25    30
     7    14    21    28    35    42
    11    22    33    44    55    66

Or you can use importdata.



来源:https://stackoverflow.com/questions/1892357/txt-files-in-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!