【发布时间】:2014-03-17 12:22:06
【问题描述】:
我正在尝试执行以下操作:
导入一个大数据文件(类似于 300x50000)。然后我需要对其中的一些列进行后处理:
- 取特定列的平均值(例如第 3、7、18 等)
- 使用 CaseX_3rd、CaseX_7th、CaseX_18th 之类的内容保存每一列
- 针对另一个向量(某个位置)绘制 + 保存每个 CaseX_3rd 等的平均值。
最后,对另一个案例重复上述操作。
谁能推荐一些 Matlab 代码来做到这一点?我仍然对 Matlab 的正常工作缺乏经验。这就是我卡住的地方:
% loading files
Case7 = dlmread('Case7.dat', '', 3, 0);
% number of columns that I need data from (no particular sequence..)
cols = [16, 28, 40, 52, 64, 76, 88, 100];
% Generating colum names
fid = fopen('FNumber.txt', 'wt');
for i = 1:length(cols)
fprintf(fid, 'FNumber_%d\n', i);
end
% Reading dat file with colum names
FNumber = importdata('FNumber.txt');
% Trying to assign the column with the name
% Length of FNumber ought to be the same as column numbers wanted
% This is where I am properly stuck:
for i=1:length(cols)
ith_col = num2str(col(i));
ith_FNumber = FNumber{i}
ith_FNumber = Case7(:,i) % I know this doesn't work, but have no alternative
end
% The above isn't working, so I'm not going to proceed with the rest of
% the pseudo-code.
提前致谢。
【问题讨论】:
-
如果您发布您已经尝试过的代码以及为什么它不起作用,您将有更好的机会获得答案。 SO上的人通常不喜欢为别人编写整个代码......
-
事实上,SO 上的人通常也不喜欢自己编写整个代码;-)
-
不想获得免费代码...但感谢“友好”的建议。
-
感谢您发布代码!有一件事是,在使用不同的功能读取文件之前,您不会关闭写入 (
'Fnumber.txt') 的文件……我不知道这是否会导致问题。第二个是,你能解释一下“这不起作用”是什么意思吗?在我看来它不应该给出任何语法错误,所以我没有看到直接的问题......
标签: matlab variables for-loop import save