how to display / recall data in matlab

11 ビュー (過去 30 日間)
omar mahallawy
omar mahallawy 2019 年 3 月 15 日
コメント済み: Rik 2019 年 3 月 20 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by