condition exist and not exist
35 次查看(过去 30 天)
显示 更早的评论
Hello,
i would to ask how can i make a condition if the string exist in file so there is a variable for example 1. Meanwhile, if the string is not exist then there is variable equal to 0.
This is example of my file.
The name of the file is F1_ION17009.FRS & F1_ION17010.FRS.
This is example of my code:
clear all;
clc;
% output=fopen('ND_ISK1_ISK3.txt','wt');
start=17000; % start_date 1/1/2017
bsl_header=[];
% ISK1_ISK3=[];
% Date=[];
% BSL=[];
% Epoch=[];
% Sat1=[];
% Sat2=[];
% Residual=[];
%load file
% i=10
for i = 9:10
y_doy=start+i;
date=start+i;
name=num2str(y_doy);
file=str2double(name);
load= sprintf('F1_ION%s.FRS',name);
fprintf('%s\n',load)
myfile=fopen(load);
bsl13num=[];
bsl15num=[];
while 1;
readfile=fgetl(myfile);
bsl13=findstr(readfile,'ISK1 ISK1 ISK3 ISK3');
bsl15=findstr(readfile,'ISK1 ISK1 ISK5 ISK5');
if ~isempty(bsl13);
bsl13num=str2double(readfile(2:4));
end
if ~isempty(bsl15);
bsl15num=str2double(readfile(2:4));
end
if readfile==-1
fprintf('Done taking baseline ISK1-ISK3 number information for %s file \n',load);
break;
end
end
end
bsl_header=[bsl_header;file bsl13num bsl15num];
end
The ouput that i want should be like this:
bsl_header=[17009 0 9;17010 10 11]
Can someone help me about this question?
3 个评论
Bob Thompson
2021-2-22
Getting an existance check to return 1 or 0 just means you need to apply some logic to it. I'm not sure how you're using the 1 and 0 in your desired output, or where you're looking to do the check within your code. Are you trying to inject a 0 in your output array if no string is found in the findstr check?
To check if a string exists, I recommend just applying logic to look for an empty findstr result.
existcheck = ~isempty(bsl13num);
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Argument Definitions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!