필터 지우기
필터 지우기

Restrict a column of data by two numerical constraints

조회 수: 4 (최근 30일)
jgillis16
jgillis16 2015년 8월 3일
댓글: jgillis16 2015년 8월 3일
I am trying to restrict my data from column 3 in the text file (attached) from numbers 11.78 =< x <= 13.25. For some reason, it is including numbers higher than the upper limit set. How would I fix this/ where am I going wrong?
My code is below:
fidi = fopen('virgoclusterrm.txt','rt');
Glxc = textscan(fidi, '%s', 'Delimiter','|');
frewind(fidi)
Glxcs = textscan(fidi, '%s', 'EndOfLine','\r\n');
fclose(fidi);
dlen = 18*fix(length(Glxc{:})/18); % Set Row Length
Glxcr = reshape(Glxc{:}(1:dlen), 18, [])'; % Reshape & Transpose
LIdx=str2double(Glxcr(:,3))>11.77
LIdx=str2double(Glxcr(:,3))<13.25
NewGlxc = Glxcs{:}(LIdx,:); % Rows Of New Array
fido = fopen('virgoclusterrmra.txt','wt')
fprintf(fido, '%s\n', NewGlxc{:});
fclose(fido)

채택된 답변

Sebastian Castro
Sebastian Castro 2015년 8월 3일
So, you have 2 lines that define separate values for LIdx. So, the second line overwrites LIdx from the first line such that you're only meeting half the constraints that you want.
You may want to refactor your indices to tackle both upper and lower limits in the same statement:
LIdx= (str2double(Glxcr(:,3))>11.77) & (str2double(Glxcr(:,3))<13.25)
- Sebastian

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by