Take specific element value in a matrix

조회 수: 13 (최근 30일)
Bui
Bui 2011년 4월 19일
How can i take a specific element value inside a matrix? For example; A = [a11 a12 a13 a14; a21 a22 a23 a24; a31 a32 a33 a34; a41 a42 a43 a44]
i want to make V1 = a11, D1 = a12, V2 = a13, D2 = a14.
Any idea? :]
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2011년 4월 19일
Why do you want to do that in the first place. Variable proliferation will become a nightmare (not to talk about referencing those values).

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

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2011년 4월 19일
example
A = randi(160,4)
A1row = num2cell(A(1,:))
[V1, D1, V2, D2] = A1row{:}
or
V1 = A1(1,1), D1 = A1(1,2), V2 = A1(1,3), D2 = A1(1,4)
or
k = 0;
for j = {'V1' 'D1' 'V2' 'D2'}
k = k +1;
eval([ j{:} ' = ' num2str(A(1,k))])
end
and etc
invers problem
VDinput = num2cell(randi(200,1,4))
[V1, D1, V2, D2] =VDinput{:}
A(1,:) = [V1, D1, V2, D2]
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2011년 4월 19일
I would avoid teaching people eval...

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by