Help with MATLAB basics

I'm new to MATLAB so I'm having some trouble here. Can anyone tell me how to find a specific element in a list? something like the in operator for python. Thanks :)

댓글 수: 1

Jan
Jan 2013년 5월 13일
This is a Matlab forum. Although it is likely, that you find someone who speaks Matlab and Python, it is more likely, that you get a fast answer, if you explain in words, what the program should do.

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

 채택된 답변

Jan
Jan 2013년 5월 13일

1 개 추천

Most likely you want:
index = find(strcmp(list, element), 1);
if list is a cell string, or:
index = find(list == element, 1);
if list is a numerical vector.

댓글 수: 1

Or, if the "target" number is a floating point number, see the FAQ:
% instead of a == b
% use:
areEssentiallyEqual = abs(a-b) < tol
% for some small value of tol relative to a and b
% perhaps defined using eps(a) and/or eps(b)
theElementIndex = find(areEssentiallyEqual);
or you might want to use ismember(), which is useful in certain cases.

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

추가 답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2013년 5월 13일

1 개 추천

First I should to point you to various get-started documentation...
Then I'd suggest that you read the documentation of:
help
find
strfind
findstr
isequal
HTH

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

2013년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by