How to read elements from a computed matrix without define a new variable?

Dear all,
I am having a question about matrix computation. For example, a matrix A is calculated by an expression, . I am only interested in the element . Simply I can do and . I am wondering whether there is a way to do this without defining A. This line of code is not legal in MATLAB but it shows my goal clearly, .
Thanks!

댓글 수: 7

This feature was asked for future versions, but the answer of the staff was for that you need to create the variable anyways, so you are only losing legilability, not wining performance.
Mathematically, you can just compute the first element as
a = exp(B(1,:)*C(:,1)+D(1));
Yize Wang
Yize Wang 2019년 5월 10일
편집: Yize Wang 2019년 5월 10일
Thank you for your fast answer. Loss of legilability is exactly what I am trying to avoid. Mathematical way works fine for me but may be confusing to other readers. Thanks!
Of course,
a = exp(B(1,:)*C(:,1)+D(1));
is wrong in general.
It's true if, e.g., B*C+D is a diagonal matrix.
Eeeeeemmmm, Torsten... this equation is true always...
If you want to check:
A = rand(3);B = rand(3); C = A*B; D = A(1,:)*B(:,1); D==C(1,1)
The matrix exponential of a matrix is not equal to the matrix where all of its elements are "exponentialized".
Yize Wang, this is the easiest way and fastest to do it as I know. If you are concern about legibility, you can encapsulate this piece of code in a function called get_1_comp_system or some cool name (I'm not good at all naming).
Stephen23
Stephen23 2019년 5월 10일
편집: Stephen23 2019년 5월 10일
"Eeeeeemmmm, Torsten... this equation is true always..."
Except that you did not take into account the matrix exponential shown in the original question.

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

 채택된 답변

Stephen23
Stephen23 2019년 5월 10일
편집: Stephen23 2019년 5월 10일
MATLAB does not allow indexing into the results of operations. You can either use a temporary variable (which is probably the most efficient solution), or you could call subsref directly:
>> B = rand(3);
>> C = rand(3);
>> D = rand(3);
>> a = subsref(expm(B*C+D),substruct('()',{1,1}))
a = 8.6593
>> A = expm(B*C+D) % for comparison:
A =
8.6593 7.3898 6.2134
13.1945 16.0237 11.6736
13.1316 13.8705 11.8273

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 5월 10일

편집:

2019년 5월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by