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

2 ビュー (過去 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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by