필터 지우기
필터 지우기

Indexing a matrix that's not in the workspace

조회 수: 1 (최근 30일)
Matthew Calvin
Matthew Calvin 2019년 7월 31일
답변: TADA 2019년 7월 31일
I'm reading through someone else's code and trying to understand it. One thing it would be very helpful to be able to do is to be able to see what entries are in specific places in certain matrixes without having to name them. So for example their code might have at some point:
[1,2,3,4]
What I'd like to be able to do in the Command Window is:
>> [1,2,3,4](3)
ans =
3
but the code as written doesn't work. Is there a way to do this other than naming the variable and then checking the position?

채택된 답변

TADA
TADA 2019년 7월 31일
you can write a utility function to do that
function value = debugPrint(a, i)
value = a(i);
end
%% or using an anonymous function:
debugPrint = @(a,i) a(i);
now you can call it like that:
debugPrint([1,2,3,4], 3)
ans =
3
or use the builtin indexing function subsref for that:
subsref([1,2,3,4], substruct('()', {3}))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by