Select values from an array to evalaute data training

조회 수: 7 (최근 30일)
Rafael Zanetti
Rafael Zanetti 2022년 12월 18일
댓글: the cyclist 2022년 12월 18일
Hi everyone,
I've tried extract values of an array to evaluate a data, for example my vector of datas is:
X = [0:0.05:1]';
My data points to evaluate are Xval = [0.3 0.65 0.75 0.8]';
So I have to isolate the values presented in Xval from X, I tried to use idx unsuccessfully, if someone could help me in this case I thank you!

채택된 답변

the cyclist
the cyclist 2022년 12월 18일
X = [0:0.05:1]';
Xval = [0.3 0.65 0.75 0.8]';
[tf,loc] = ismembertol(Xval,X) % Using ismembertol rather than ismember, to avoid floating point issues
tf = 4×1 logical array
1 1 1 1
loc = 4×1
7 14 16 17
  댓글 수: 2
Rafael Zanetti
Rafael Zanetti 2022년 12월 18일
I thank you, it was very functional in matlab, but enjoying the question, do you would know how to apply this formulation in octave due the miss of function "ismembertol"? I asking that because only "ismemeber" is available there in Octave.
One more time, I thank you!
the cyclist
the cyclist 2022년 12월 18일
Here is a very different approach. The method is to do all possible subtractions between X and Xval, and find the ones that are very small. Just like in the ismembertol method, this is done to within a tolerance. (I just used the default tolerance in that solution.)
MATLAB will implicitly expand the dimensions of the two vectors, to do the matrix subtraction. I don't know if Octave will do that. You might need to do the subtraction using bsxfun instead. (I don't know if Octave has that either. I guess you might need to do all the subtractions in for loops.)
The variable row here gives the same info as the variable loc above. You might want to use the col variable for error-checking that all values were found.
X = [0:0.05:1]';
Xval = [0.3 0.65 0.75 0.8]';
tol = 1.e-6;
[row,col] = find(abs(X - Xval')<tol)
row = 4×1
7 14 16 17
col = 4×1
1 2 3 4

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by