필터 지우기
필터 지우기

Fortran to Matlab converting the "where" statement

조회 수: 1 (최근 30일)
msh
msh 2014년 6월 10일
편집: James Tursa 2014년 6월 11일
Hi,
I would like to know how is possible to convert the particular statement from fortran to matlab
where (abs(A-B)>e)
no_converge=1
elsewhere
no_converge=0
end where
A and B are arrays of some particular dimensions, and e is a scalar. I have to say that I am not that familiar with either programming languages. However, what I understood from some sources the particular statement takes the element per element difference of those arrays and evaluates whether the difference is higher or lower from a particular scalar, e. For this example, assume that it is very small, e.g e=0.0001.
I have used the f2matlab but it does very poor job on this fortran statement. In case it helps this is a code from F90.
I am wondering whether the quivalent for a matlab is something like this:
if abs(A-B)>e
no_converge=1 ;
else
no_converge=0 ;
end
However, I am not sure whether this is quite general or not. In other words, i am not sure for whatever the condition is or the A's and B's a simple "if" statement does the trick.
I will really appreciate any suggestions here. In case that it helps, this part of the code, is very crucial since it checks whether a whole distribution converges to a particular distribution that is needed.
Many thanks

채택된 답변

James Tursa
James Tursa 2014년 6월 10일
편집: James Tursa 2014년 6월 11일
no_converge= zeros(size(A));
no_converge( abs(A-B) > e ) = 1;
or
no_converge= double( abs(A-B) > e );
or if you can use no_converge as a logical instead of a double:
no_converge= abs(A-B) > e;
  댓글 수: 6
James Tursa
James Tursa 2014년 6월 11일
편집: James Tursa 2014년 6월 11일
@Safis: What you have written makes absolutely no sense to me at all. The WHERE construct is specifically set up to do element-by-element assignments to arrays controlled by the logical array mask. The variable being assigned to, no_converge, only makes sense in this context if it is an array. Can you double check your code? In addition to the INTEGER statement, is no_converge also part of a separate DIMENSION statement?
msh
msh 2014년 6월 11일
@James Tursa: You are right, the authors of the code indeed have declared the no_converge as an array of the same dimensions as in A and B. I got confused because they also have another no_converge_f variable declared as an integer. I now i believe I got it. Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by