Matlab find() function in script

In summary, the conversation is about using the statement [ in a Matlab script and how to find matrix indices for which the statement M==10 is true. The solution is to use () instead of [] for the find argument. The person asking for help was a beginner in Matlab.
  • #1
phyhari
2
0
SOLVED.
Hi All!
Brief version:
I would like to use statement starting with [ in Matlab script. Is it possible, if yes, how?

Longer version:
I'm writing code in matlab. I need to find matrix indices, for which the statement M==10 is true. (I found find() function, which is perfect for the task).

[r,c]=find[M==10];

It works perfectly within the command window, but not in my script.
I get an error message, stating: parse error at '[' ... not valid MATLAB script
Can you help, or I must write an algorithm for finding indices? :S

Thanks in advance!
 
Last edited:
Physics news on Phys.org
  • #2
Use (), not [] for the find argument
 
  • #3
Thank you! :) That was the problem. As you can see I'm just started coding in matlab...
 

Related to Matlab find() function in script

What is the purpose of the "find()" function in a Matlab script?

The "find()" function in Matlab is used to locate the indices of array elements that meet a certain condition. It is commonly used to find specific values or elements within an array.

How do you use the "find()" function in a Matlab script?

To use the "find()" function, you need to provide an array and a condition to search for. The function will then return the indices of the elements that meet the condition. For example, find(A > 5) will return the indices of all elements in array A that are greater than 5.

Can the "find()" function be used to search for multiple conditions?

Yes, the "find()" function can search for multiple conditions by using logical operators such as "&&" (and), "||" (or), and "~" (not). For example, find(A > 5 && A < 10) will return the indices of elements in array A that are both greater than 5 and less than 10.

Is the "find()" function case-sensitive?

No, the "find()" function is not case-sensitive. This means that it will return the same results regardless of whether the condition is written in uppercase or lowercase letters.

Are there any alternative functions to "find()" in Matlab?

Yes, there are alternative functions in Matlab that serve similar purposes to the "find()" function. Some of these functions include "logical indexing", "ismember()", and "findgroups()". It is important to choose the most appropriate function for your specific task.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top