PARFOR loop can not run due to the way variable "M" is used.

1 vue (au cours des 30 derniers jours)
Pouya
Pouya le 4 Fév 2022
Commenté : Raymond Norris le 8 Fév 2022
Hello,
I'm wondering what I can do to variable "M" to make it PARFOR - friendly while keeping it's function.
Any help is appricated - Thanks in advance.
Please find the code below:
clc
clear all
path = 'SW_OPER_MAGA_HR_1B_20170214T000000_20170214T235959_0505_MDR_MAG_HR.cdf';
info = cdfinfo(path) ;
vars=info.Variables ;
data=cdfread(path,'Variables',{'Latitude'});
timestamp=(cdfread(path,'Variables',{'Timestamp'}));
parfor i=1:length(timestamp);
fprintf('processing %d of %d time step one',i,length(timestamp));
datenum(i) = todatenum(timestamp{i});
[year(i), month(i),day(i) ,hh(i),mm(i),ss(i)]=datevec( todatenum(timestamp{i}));
fprintf(' - Time step one calc done \n');
end
parfor i=1:length(mm);
fprintf('processing %d of %d time step two',i,length(mm));
time(i) = hh(i) + mm(i)/60 +(ss(i)/3600);
fprintf(' - Time step two calc done \n');
end
UT = hh+(mm/60)+(ss/3600);
data1 = cell2mat(data);
lat = data1(:,1);
fprintf('start of find...');
f0 = find(UT>0&UT<24);
fprintf(' - find done\n');
f=f0;
f1 = horzcat(f,f(end)+1:f(end));
fprintf(' - f1 done\n');
fprintf('start of cell2mat data1...');
data1=cell2mat(cdfread(path,'Variables',{'Latitude','Longitude','Radius'}));
fprintf(' - cell2mat data1 done\n');
parfor i=1:length(f1);
fprintf('processing %d of %d variables',i,length(f1));
Alt(i) = (data1(f1(i),3)/1000);
fprintf(' - Variables calc done \n');
end
parfor i=1:length(f1);
fprintf('processing %d of %d ms',i,length(f1));
M(i,1) = data1(f1(i),1);
M(i,2) = data1(f1(i),2);
M(i,3) = Alt(i);
M(i,4) = datenum(f1(i));
fprintf(' - ms calc done \n');
end

Réponse acceptée

Raymond Norris
Raymond Norris le 4 Fév 2022
Collapse
M(i,1) = data1(f1(i),1);
M(i,2) = data1(f1(i),2);
M(i,3) = Alt(i);
M(i,4) = datenum(f1(i));
to
M(i,:) = [data1(f1(i),1) data1(f1(i),2) Alt(i) datenum(f1(i))];
By the way, there's a MATLAB function, datenum. You might consider using a different variable name.
  2 commentaires
Pouya
Pouya le 5 Fév 2022
Modifié(e) : Pouya le 5 Fév 2022
Thank you Raymond, it worked like a charm!
Can you explain your point on "datenum" a bit further. I didn't quite get it.
Raymond Norris
Raymond Norris le 8 Fév 2022
In the call to
datenum(i) = todatenum(timestamp{i});
you are overwriting the MATLAB function, datenum.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by