how to display / recall data in matlab

3 Ansichten (letzte 30 Tage)
omar mahallawy
omar mahallawy am 15 Mär. 2019
Kommentiert: Rik am 20 Mär. 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 Kommentare
Rik
Rik am 16 Mär. 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 am 16 Mär. 2019
Bearbeitet: omar mahallawy am 16 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Rik
Rik am 16 Mär. 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 Kommentar
Rik
Rik am 20 Mär. 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.

Melden Sie sich an, um zu kommentieren.


TADA
TADA am 16 Mär. 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);

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by