I want to get output from below code but Matlab thrown Error:
[1 2 3 4](2)
My desired output is 2.
Note: I need one line answer without using any function.
Thanks

답변 (2개)

Walter Roberson
Walter Roberson 2015년 6월 14일
편집: Walter Roberson 2015년 6월 14일

1 개 추천

I would probably use something like:
Index = @(V,K) V(K);
and then Index([1 2 3 4],2)
If I felt especially obscure there would always be
subsref([1 2 3 4], struct('type','()','subs', {[2]})
which is what will happen internally
Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 14일
편집: Azzi Abdelmalek 2015년 6월 14일

0 개 추천

v=[1 2 3 4]
v(2)
If you want one line, then just write
v=2

댓글 수: 1

ar fa
ar fa 2015년 6월 14일
Thanks Abdelmalek but this is not my answer.

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

질문:

2015년 6월 14일

편집:

2015년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by