how to display / recall data in matlab
조회 수: 11 (최근 30일)
이전 댓글 표시
i have such a long code that is really hard to reverse engineer for what i need.
i just need a code that would display which variables that have been used that calculate the matrix.
example:-
A=[10 20 30 40 50]
B= (A.*2)+1 %irreversable code
C=B(B > 40 & B < 80)
C= 41 61 81
D= 20 30 40
to elaborate furthur, i have an array of inputs, 27 elements to be exact, placed into many if conditions
and equations, now i need to know which inputs have passed all my if conditions,(REVERSE ENGINEER)
댓글 수: 3
Rik
2019년 3월 16일
So you mean you need to deduce which elements from A are still present in D?
It sounds like your code should be better structured to allow for something like this, instead of treating your own code as a black box.
답변 (2개)
Rik
2019년 3월 16일
As long as the input array A has sufficiently unique values, you can use either ismember or ismembertol.
A=[10 20 30 40 50]
blackbox=@(x) x(x*2+1 > 40 & x*2+1 < 80);
D=blackbox(A);
tol=1e-6;%use an absolute tolerance to account for float rounding
L=ismembertol(A,D,tol,'DataScale',1);
%exp(log(3))==3 will return false, ismembertol can account for this
%L contains the positions in A where it shares elements with D
Note that your code example is incorrect, since C would not contain 81, as that is larger than 80, not smaller.
댓글 수: 1
Rik
2019년 3월 20일
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.
TADA
2019년 3월 16일
Seems To Me Like What You Want Is To Keep Track Of All Your If Conditions With A Logical Index
index = B > 40 & B < 80;
% your next conditions go here
index = index & ~isnan(B); % obviously this condition makes no sence, but I'm improvising
C = B(index);
D = A(index);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!