For-looping output not adequate
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Jan
on 1 Aug 2022
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 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!