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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Raymond Norris
Raymond Norris el 4 de Feb. de 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 comentarios
Pouya
Pouya el 5 de Feb. de 2022
Editada: Pouya el 5 de Feb. de 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 el 8 de Feb. de 2022
In the call to
datenum(i) = todatenum(timestamp{i});
you are overwriting the MATLAB function, datenum.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by