![]() |
循环MATLAB问题
no time scores 1 10 123 2 11 22 3 12 22 4 50 55 5 60 22 6 70 66 . . . . . . nnn 以上是我的txt文件的内容(一千行)。
1st column - number of samples 2nd column - time (from beginning to end ->accumulated) 3rd column - scores 我想创建一个新文件,该文件将是分数的每三个样本的总和除以同一样本的时间差。 eg (123+22+22)/ (12-10) = 167/2 = 83.5 (55+22+66)/(70-50) = 143/20 = 7.15 新的txt文件 83.5 7.15 . . . n 到目前为止,我有此代码: fid=fopen('data.txt') data = textscan(fid,'%*d %d %d') time = (data{1}) score= (data{2}) for sample=1:length(score) ..... // I'm stucked here .. end .... [B]回答:[/B] %# Easier to load with importdata data = importdata('data.txt',' ',1); %# Get the number of rows n = size(data,1); %# Column IDs time = 2;score = 3; %# The interval size (3 in your example) interval = 3; %# Pre-allocate space new_data = zeros(numel(interval:interval:n),1); %# For each new element in the new data index = 1; %# This will ignore elements past the closest (floor) multiple of 3 as requested for i = interval:interval:n %# First and last elements in a batch a = i-interval+1; b = i; %# Compute the new data new_data(index) = sum( data(a:b,score) )/(data(b,time)-data(a,time)); %# Increment index = index+1; end [url=https://stackoverflow.com/questions/2957885]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:16。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.