Matlab find() function in script

  • Context: MATLAB 
  • Thread starter Thread starter phyhari
  • Start date Start date
  • Tags Tags
    Function Matlab
Click For Summary
SUMMARY

The discussion centers on the use of the `find()` function in MATLAB scripts to locate matrix indices where a condition is met. The user encountered a parse error when attempting to use square brackets `[]` instead of parentheses `()`. The correct syntax for the `find()` function is to use parentheses, as demonstrated by the solution: `[r,c] = find(M == 10);`. This correction resolves the issue and allows the script to function as intended.

PREREQUISITES
  • Basic understanding of MATLAB syntax
  • Familiarity with matrix operations in MATLAB
  • Knowledge of logical indexing in MATLAB
  • Experience with MATLAB script execution
NEXT STEPS
  • Explore MATLAB's logical indexing techniques
  • Learn about MATLAB function syntax and conventions
  • Investigate error handling in MATLAB scripts
  • Practice using the `find()` function with different conditions
USEFUL FOR

Beginner MATLAB programmers, data analysts using MATLAB for matrix operations, and anyone looking to troubleshoot MATLAB script errors.

phyhari
Messages
2
Reaction score
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
Use (), not [] for the find argument
 
Thank you! :) That was the problem. As you can see I'm just started coding in matlab...
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K