how to display / recall data in matlab

12 views (last 30 days)
omar mahallawy
omar mahallawy on 15 Mar 2019
Commented: Rik on 20 Mar 2019
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 Comments
Rik
Rik on 16 Mar 2019
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 on 16 Mar 2019
Edited: omar mahallawy on 16 Mar 2019
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.

Sign in to comment.

Answers (2)

Rik
Rik on 16 Mar 2019
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 Comment
Rik
Rik on 20 Mar 2019
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.

Sign in to comment.


TADA
TADA on 16 Mar 2019
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);

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!