How to change this for loop into parfor loop?
Afficher commentaires plus anciens
Hi guys, I'm new to the MATLAB. I am currently trying to change a for loop into a parfor loop, but after many attempts altering my codes, I still cannot seem to make it work. I either get variable classification issue or I get transparency issue. I hope that someone can help me translate my codes into a parfor loop. Here are the codes:
% Removing colums of data with y consecutive data points that have same values with in each column. data.txt consist of a n by m matrix with the first row being names.
load data.txt
nrow=size(data,1);
ncol=size(data,2);
y=10;
for j = 1:1:ncol
i = 2;
while i <= nrow - (y - 1)
if data(i,j) == data(i+1,j)
data_vec = data(i:i+y-1,j);
diff_vec = data_vec(2:end,1) - data_vec(1:end-1,1);
temp = sort(diff_vec);
if temp(1,1) ==0 && temp(end,1) == 0
data(:,j) = 0;
i = nrow;
else
i = i + find(diff_vec,1) - 1;
end
clearvars temp data_vec diff_vec
end
i = i + 1;
end
end
data( :, ~any(data,1) ) = [];
clearvars nrow ncol j i
Thank you for your help in advance :).
Réponse acceptée
Plus de réponses (1)
Will
le 9 Déc 2017
0 votes
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!