Help with MATLAB basics
1 view (last 30 days)
Show older comments
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 Comment
Jan
on 13 May 2013
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.
Accepted Answer
Jan
on 13 May 2013
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 Comment
Image Analyst
on 13 May 2013
% 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.
More Answers (1)
Bjorn Gustavsson
on 13 May 2013
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
0 Comments
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!