How to check each number in a user given vector
2 次查看(过去 30 天)
显示 更早的评论
The following is the function I am trying to build. If a user doesnt give any information it work, however I am trying to have it so that when the user enters an arbitrary 1x4 vector of ones and zeros, the corresponding information is pulled. Not everything is shown in this code only the parts I think are pertinent to this question.
function fetchRINEX(days2get, startUTC, GNSSflag)
% Simple script to retrive GPS, GALILEO, BEIDOU, and GLONASS RINEX based navigation data files.
% GNSSflag = [GPSflag Galileoflag beidouflag glonassflag]
% flag = 1 Retrieve that data
if nargin==0
days2get = 1;
end
if nargin<2
startUTC = fix(clock);
end
if nargin<3
GNSSflag = [0 0 0 0];
GNSS = {'GPS','GALILEO','GLONASS','BEIDOU'};
[indx,tf] = listdlg('ListString',GNSS);
end
%%%%%%%%% This is where I need help to check which column in the vector is a 1 and which is a zero
% and then execute the following code with respect to the 1's %%%%%%%%%%%%%%%%%%%%%%%
for i=1:days2get
if sum(indx==1)>0 % If GPS is selected from the selection box, the following code will be executed.
% Build the directory string for GPS
dirStr = sprintf('/gnss/data/daily/2020/%03d/20n/', doy(i));
fileStr = sprintf('brdc%03d0.20n.Z', doy(i)); % Note this does not work for data set prior to 2000
cd(ftpobj, dirStr);
mget(ftpobj, fileStr, '.');
end
if sum(indx==2)>0 % If GALILEO is selected from the selection box, the following code will be executed.
% Build the directory string for GALILEO
dirStr = sprintf('/gnss/data/daily/2020/%03d/20l/', doy(i));
fileStr = sprintf('glps%03d0.20l.Z', doy(i)); % Note this does not work for data set prior to 2000
cd(ftpobj, dirStr);
mget(ftpobj, fileStr, '.');
end
if sum(indx==3)>0 % If GLONASS is selected from the selection box, the following code will be executed.
% Build the directory string for GLONASS
dirStr = sprintf('/gnss/data/daily/2020/%03d/20g/', doy(i));
fileStr = sprintf('brdc%03d0.20g.Z', doy(i)); % Note this does not work for data set prior to 2000
cd(ftpobj, dirStr);
mget(ftpobj, fileStr, '.');
end
1 个评论
dpb
2020-6-25
if nargin<3
GNSSflag = [0 0 0 0];
GNSS = {'GPS','GALILEO','GLONASS','BEIDOU'};
[indx,tf] = listdlg('ListString',GNSS);
end
Just a comment on your input processing -- if the user passes the third input argument, then the variables indx,tf are never defined and your next loop will die.
Need a default condition set so is definied for all cases.
回答(1 个)
dpb
2020-6-25
编辑:dpb
2020-6-26
if nargin<3
GNSSflag = [0 0 0 0];
GNSS = {'GPS','GALILEO','GLONASS','BEIDOU'};
[indx,tf] = listdlg('ListString',GNSS);
end
if ~tf, error("No Satellite Selected. Aborting"), end % User canceled out
for i=1:days2get
for j=1:numel(indx) % for each selected satellite for each day
switch indx(j)
case 1 % If GPS is selected from the selection box, the following code will be executed.
% Build the directory string for GPS
dirStr = sprintf('/gnss/data/daily/2020/%03d/20n/', doy(i));
fileStr = sprintf('brdc%03d0.20n.Z', doy(i)); % Note this does not work for data set prior to 2000
cd(ftpobj, dirStr);
mget(ftpobj, fileStr, '.');
case 2 % If GALILEO is selected from the selection box, the following code will be executed.
% Build the directory string for GALILEO
dirStr = sprintf('/gnss/data/daily/2020/%03d/20l/', doy(i));
fileStr = sprintf('glps%03d0.20l.Z', doy(i)); % Note this does not work for data set prior to 2000
cd(ftpobj, dirStr);
mget(ftpobj, fileStr, '.');
case 3 % If GLONASS is selected from the selection box, the following code will be executed.
% Build the directory string for GLONASS
dirStr = sprintf('/gnss/data/daily/2020/%03d/20g/', doy(i));
fileStr = sprintf('brdc%03d0.20g.Z', doy(i)); % Note this does not work for data set prior to 2000
cd(ftpobj, dirStr);
mget(ftpobj, fileStr, '.');
case 4
....
end
end
Above assumes doing each day first; depending on the data storage organization it may be more efficient to swap the hierarchy of the loops and to process each satellite all days in order instead.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!