Matlab:写入文件

时间:2015-06-17 14:29:11

标签: arrays matlab loops math for-loop

  

我想将mean_2 .... mean_8,std_2 .... std_8和coVariance存储为文件中的单独列。请帮帮忙?

此代码使用256个时间帧计算Erp信号的IntervalFeatures  并绘制它们  数据点存储在A

___________ HowTheCodeWorks ________________________________________________

每个1x4滑动子矩阵成为一列  例如: - 如果A是1x6,你将得到1-2-3-4,2-3-4-5,3-4-5-6作为一列  以3列结尾。对于1x10矩阵,你会得到7列

计算每列的平均值

使用相应列的平均值减去列的每个值  最后是逐元素的平方,每列的意思  然后按元素方式获取输出。

A=firstElec;

%___________Length2_____________________
reshaped_2 = im2col(A,[1 2],'sliding');
mean_2 = mean(reshaped_2);
out1 = bsxfun(@minus,reshaped_2,mean_2);
std_2 = sqrt(mean(out1.^2))

%___________Length4_____________________
reshaped_4 = im2col(A,[1 4],'sliding');
mean_4 = mean(reshaped_4);
out2 = bsxfun(@minus,reshaped_4,mean_4);
std_4 = sqrt(mean(out2.^2))

%___________Length8_____________________
reshaped_8 = im2col(A,[1 8],'sliding');
mean_8 = mean(reshaped_8);
out3 = bsxfun(@minus,reshaped_8,mean_8);
std_8 = sqrt(mean(out3.^2))

%___________CoVariance__________________
begInt = 1;
endInt =256;
l=endInt - begInt + 1;
arrayCovar = zeros(1,257);
j=1;
for k=1:256

coVar = 1/l *((A(k)*k) - (mean(A(k:j))*((begInt + endInt)/2)));
j= 1+k;
arrayCovar(k)=coVar;
end

coVariance = arrayCovar(:,1:256);
disp(coVariance)

2 个答案:

答案 0 :(得分:1)

如果你想让矩阵显示在每一列中,那就太难看了。如果我正确地解释您的请求,您将连接行向量,使它们显示为单行。那会很糟糕。

我建议你做的是将它们分开,以便每行向量分开。请使用dlmwrite

var Model = Backbone.Model.extend({
    defaults: {
        'netPrice': 0.0,
        'vatRate': 0.0
    },

    initialize: function () {
        this.computedFields = new Backbone.ComputedFields(this);
    },

    computed: {
        grossPrice: {
            depends: ['netPrice', 'vatRate'],
            get: function (fields) {
                return fields.netPrice * (1 + fields.vatRate / 100);
            }
        }
    }
});

model = new Model({ netPrice: 100, vatRate: 20});
model.get('grossPrice')     // -> 120 is returned

答案 1 :(得分:0)

使用下面的函数(usage function x = Cellify(varargin) maxSize = [0, 0]; totalSize = [0, 0]; for i = 1:nargin maxSize = max([maxSize; size(varargin{i})]); totalSize = sum([totalSize; size(varargin{i})]); end x = cell(maxSize(1), totalSize(2)); columnShift = 0; for i = 1:nargin x(1:size(varargin{i}, 1), 1+columnShift:size(varargin{i}, 2)+columnShift) = num2cell(varargin{i}); columnShift = size(varargin{i}, 2); end end )将向量转换为单个单元格,然后使用这个优秀的函数(cell2csv)写入文件。

{{1}}