为什么我收到这个错误使用cumsum时:“无效的数据类型。第一个输入参数必须是一个数字或逻辑。”?
12个视图(30天)
显示旧的评论
你好,
我有很少经验的一位心理学家在Matlab,我只是想运行代码(见附件)。函数是:
函数[H] = dfaedit (file_name、plot_flag outfile_flag, out_command_flag)
当调用输入参数的因数我总是收到错误:
错误使用cumsum
无效的数据类型。第一个输入参数必须是数字或逻辑。
错误dfaedit(44)行
和= cumsum (x);
(我已经尝试使用不同的文件类型。.dat, txt . csv),不同的输入变量(矩阵表、向量等)和从向量提取数据,但无论我得到同样的cumsum输入错误。整数的数据本身就是一个列值。
起初,我以为我的数据没有数值但尝试了上面提到的所有步骤后我的想法。有人能帮帮我吗?
如果这似乎是显而易见的:对不起)
谢谢!
接受的答案
Torsten
2022年1月8日
试试这个:
函数主要
file_name =“sample_test.txt”;
H = dfaedit (file_name, 1, 1, 1)
结束
函数[H] = dfaedit (file_name、plot_flag outfile_flag, out_command_flag)
% DFA计算和情节去趋势波动
%
%的一维时间序列在一列文本文件名为“file_name”,
% DFA执行去趋势波动分析这些数据。它首先将
%的数据然后分区成不同的大小子集的大小
%不同MinBox(默认= 4)MaxBox(默认= 1/4长度的数据)。
%每个子集的大小,最好的拟合趋势线
%和均方根计算剩余(Q)。log10的
%的波动量(Q)策划反对log10点的一个子集。
%这回归的斜率估计分形的赫斯特指数(H)。
%维度可以计算为2 h。
%
%如果plot_flag = 1,那么创建一个回归的阴谋。如果outfile_flag = 1,文件名称,H
%和r ^ 2是附加到一个文本文件“dfa_results.txt”。如果out_command_flag = 1,数据
%,回归的基础图输出到命令窗口。
%
%的例子:dfa (“noise-f。dat ', 1, 1, 1)
%
%我使用了彭的C代码算法可在http://reylab.bidmc.harvard.edu。
%是彭等。讨论了量化的标度指数和交叉
% nonstationaryheartbeat时间系列的现象。混乱5:82 1995;87年。我向量化
%为MatLab初步计算。但是我没有触摸主循环。仍然不确定
%的算法用来计算均方根残留。
%
%的语法:
% dfa (file_name plot_flag、outfile_flag out_command_flag)
%
% r·c·施密特11-27-01
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
格式短g
% x = file_name;
fid = fopen (file_name);
data = textscan (fid检测器,' % f ');
fid =文件关闭(fid);
x = cell2mat(数据);
numberpoints =长度(x);
MinBox = 4;% minbox #的点在一个盒子里
MaxBox =升至* numberpoints;% maxbox 1/4长度的数据集
BoxSizeDensity = 4;
LogScaleFactor = (2.0, 1.0 / BoxSizeDensity);
指数= 1:numberpoints;
指数=重塑(指数、长度(指数),1);行,列向量变化百分比
%的初步计算
和= cumsum (x);
SumOfSumsSquared = cumsum(总和。*总和);
SumOfSums = cumsum(总和);
SSc = cumsum(指数。*总和);
%现在发现最适合线条和波动
%为每个盒子大小循环,从MinBox MaxBox
迭代= 1;
BoxSize = MinBox;
TempBoxSize = MinBox;
而BoxSize < = MaxBox
s = 0.0;
r1 = 1。/ (BoxSize + 1.0);
侦破= 12.0 * r1 * r1 * r1 / (1.0 - r1 * r1);
vv = BoxSize * * BoxSize (2.0 + 1.0) / 6.0;
为j = 2: numberpoints - BoxSize
dhh = SumOfSumsSquared (j + BoxSize) - SumOfSumsSquared (j - 1);
东华大学= SumOfSums (j + BoxSize) - SumOfSums (j - 1);
干热河谷= SSc (j + BoxSize) - SSc -东华大学* j (j - 1);
s = s + dhh(干热河谷*干热河谷+东华大学东华大学* * vv,干热河谷*东华大学* BoxSize) *侦破;
j = + 1;
结束
穴= (numberpoints - BoxSize) * (BoxSize + 1.0);
波动= sqrt (s /穴);
log_points_in_box(迭代,1)= log10 (BoxSize);
log_Q(迭代,1)= log10(波动);
show_results(迭代,:)=(迭代BoxSize波动log_points_in_box(迭代,1)log_Q(迭代,1)];
迭代=迭代+ 1;
%更新盒子的大小
TempBoxSize = TempBoxSize * LogScaleFactor;
而轮(TempBoxSize) < BoxSize + 1.0
TempBoxSize = TempBoxSize * LogScaleFactor;
结束
BoxSize =圆(TempBoxSize);
结束
%都框;现在通过趋势线计算H
r_trend = corrcoef (log_points_in_box log_Q);
系数= polyfit (log_points_in_box log_Q 1);
log_points_in_box r_line = polyval(系数);
%计算维度和赫斯特
H =系数(1);
D = 2 h;
%在命令窗口中显示结果
如果out_command_flag = = 1
disp (“迭代点问Log10 (pnt) Log10 (Q) ')
disp (show_results)
结束
%显示结果图
如果plot_flag = = 1
图
h =轴(“位置”(0 0 1 1),“可见”,“关闭”);
轴(“位置”,(。1。2。75 .75])
情节(log_points_in_box log_Q,“b +”)
持有在
情节(log_points_in_box r_line,“k”)
ylabel (“log10 (Q)”);
包含(“log10(分子集)”);
标题(file_name);
集(gcf,“CurrentAxes”、h);
str (1) = {[sprintf (' % 2.5 f '系数(1)),“x +”sprintf (' % 2.5 f '系数(2)),' = y, r ^ 2 = 'sprintf (' % 2.2 f 'r_trend (1、2) ^ 2),”,n =”sprintf (' % d '、长度(log_Q))]};
文本(。1,。02,str,“字形大小”10“颜色”,“r”);
str (1) = {(H = 'sprintf (' % 2.3 f 'H)' D = 'sprintf (' % 2.3 f 'D)};
文本(。5、.02 str,“字形大小”10“颜色”,“r”);
结束
% rd_results.txt结果附加到文件
如果outfile_flag = = 1
fid = fopen (“dfa_results.txt”,“一个”);
流(fid检测器,' % s % 4.4 f % 2.4 f \ n”,H file_name r_trend (1、2) ^ 2);
状态=文件关闭(fid);
结束
结束
答案(1)
明星黾
2022年1月8日
(这似乎是编写的代码
2001年
)没有意义!
函数的第一个参数
“file_name”
,我
假设
将是一个字符数组。这是后来分配到
“x”
然后是
“和”
变量指定为
cumsum (x)
。做任何形式的计算在一个字符数组(没有首先转换成一个数字表示的字符数组的元素)是不可能的。
那
抛出错误。
请返回并查看文档来确定参数应该是。
选择= weboptions (“ContentType”,“文本”);
W = webread (“//www.tianjin-qmedu.com/matlabcentral/answers/uploaded_files/857175/dfaedit.m”选择)
。