的我都开在MATLAB这个数据文件的总和:试图找到各个列
- 甲11 E 88
- 乙23女性22
- Ç55g的77
- d 66 H 44
我把它命名为Thor.dat,这是我在MATLAB代码
fid = fopen('Thor.dat')
if fid == -1
disp ('File open not successful')
else
disp ('File open is successful')
mat = textscan(fid,'%c %f %c %f')
[r c] = size(mat)
matcolsum
fclose(fid)
end
这是我使用添加数值列功能:
function outsum = matcolsum(mat)
% matcolsum finds the sum of every column in a matrix
% Returns a vector of the column sums
% Format: matcolsum(matrix)
[row, col] = size(mat);
% Preallocate the vector to the number of columns
outsum = zeros(1,col);
% Every column is being summed so the outer loop
% has to be over the columns
for i = 1:col
% Initialize the running sum to 0 for every column
runsum = 0;
for j = 1:row
runsum = runsum + mat(j,i);
end
outsum(i) = runsum;
end
end
当我运行的代码,它不断给我这个错误:输入参数“垫”是不确定的。任何人都可以请帮我吗?我真的很感激。谢谢。
我和j被matlab使用,不建议将它们用作循环计数器。 – bilaly
请注意'textscan'的输出是一个单元格数组(这里是'mat'),因此您需要使用大括号{}访问数据。 –
这里我不清楚你的预期输出是什么。你想总结...字符代码吗?预期结果的例子将非常有帮助。 –