For-looping output not adequate

1 次查看(过去 30 天)
ack
ack 2022-8-1
Hi, I would like the for-looping to extract the data from T2 variable at 4 row intervals from the last one which is 484 row to 480 to 476 etc. The current code is not extracting the data out of T2. How can I fix this? Thanks.
%from struct to matrix using function
REC = load('C:\Users\ayech\Data\COMPLETE.mat');
T1 = createDataMatrix_revised3(REC);
%transposing the matrix to turn the variables into column
T1=T1';
%removing Nan for data pre-treatment
y=any(isnan(T1),2);
T1(y,:)=[];
mult = 1 /0.5; %
time = 2;%time step 2sec
T2 = T1(:,1); %first column extraction out of T1
T3 = length(T2):-(time*mult):5; %random check
for i = length(T2):-(time*mult):5 %struct array?
new_parameter (i) = T2(i) - T2(i-(time*mult));
another_new_parameter (i) = new_parameter (i) - new_parameter(i-(time*mult));
new_parameter_max = max(T2((i-time*mult):i));
new_parameter_min = min(T2((i-time*mult):i));
new_parameter_mean = mean(T2((i-time*mult):i));
end

回答(1 个)

Jan
Jan 2022-8-1
new_parameter(i) = T2(i) - T2(i-(time*mult));
In the first iteration the i.th element of the vector new_parameter is calculated.
another_new_parameter(i) = new_parameter(i) - new_parameter(i-(time*mult))
Then this line accesses new_parameter(i-4), which was not determined before. As default its value is 0.
Are you aware, that (i-time*mult):i contains 5 indices, such there is an overlap between the subvectors? Do you mean: (i-time*mult)+1:i ?
You do not need a loop to get the min, max and mean values over blocks of 4 elements:
x = rand(484, 1);
y = reshape(x, 4, []);
ymin = min(y, [], 1);
ymax = max(y, [], 1);
ymean = mean(y, 1);
  6 个评论
ack
ack 2022-8-18
Hi Walter, thanks for pointing out. Yes, it is as you said 4 rows at a time. Is there anyway to extract data from every 4th rows and remove the others? Thanks.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by