필터 지우기
필터 지우기

condition exist and not exist

조회 수: 46 (최근 30일)
Nazrin Afiq Abdul Rahman
Nazrin Afiq Abdul Rahman 2021년 2월 22일
편집: Rik 2021년 2월 24일
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
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);
Nazrin Afiq Abdul Rahman
Nazrin Afiq Abdul Rahman 2021년 2월 24일
yeah. i got the answer already. i just simply put another condition in the script plus i had to remake the script too but its okay since i already got the answer. btw thx bob

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by