For-looping output not adequate

1 visualización (últimos 30 días)
ack
ack el 1 de Ag. de 2022
Comentada: Walter Roberson el 18 de Ag. de 2022
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

Respuestas (1)

Jan
Jan el 1 de Ag. de 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 comentarios
ack
ack el 18 de Ag. de 2022
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.
Walter Roberson
Walter Roberson el 18 de Ag. de 2022
subset = data(1:4:end,:);

Iniciar sesión para comentar.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by