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
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.
omar mahallawy
omar mahallawy 2019-3-16
编辑:omar mahallawy 2019-3-16
yes, which elements from A are present in D
noted,for your info this is my first project on matlab, and it is pretty complicated.

请先登录,再进行评论。

回答(2 个)

Rik
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
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
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);

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by