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

조회 수: 1 (최근 30일)
Pouya
Pouya 2022년 2월 4일
댓글: Raymond Norris 2022년 2월 8일
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

채택된 답변

Raymond Norris
Raymond Norris 2022년 2월 4일
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
Pouya
Pouya 2022년 2월 5일
편집: Pouya 2022년 2월 5일
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 2022년 2월 8일
In the call to
datenum(i) = todatenum(timestamp{i});
you are overwriting the MATLAB function, datenum.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by