Can someone help with my syntax error
Mostra commenti meno recenti
I'm having trouble getting this to iterate through all rows of my matrix.
the goal is simply to be able to input a random matrix, and use 2 for loops to have the program locate and fprint the row and column index for all occurences of the integer. I can't use the find function, yes this is homework.

4 Commenti
John D'Errico
il 4 Apr 2021
Please don't [ost a picture of code. That makes it difficult to help you, as we cannot then paste in your code into MATLAB. Is there a good reason why you want to make it more difficult for someone to help you?
Brendan Clark
il 4 Apr 2021
Walter Roberson
il 4 Apr 2021
As a guideline... beyond approximately five short lines, people are not going to be willing to type in code to test with. And even with short lines, if the question has to do with syntax errors, it is best to post the exact code as there could be hidden characters or something subtle that is important.
Brendan Clark
il 4 Apr 2021
Risposta accettata
Più risposte (3)
KSSV
il 4 Apr 2021
If A is your array to count number of times a number n (say 5) appears, follow:
tol = 10^-5 ;
idx = abs(A-n)<=tol ;
nnz(idx(:))
1 Commento
Brendan Clark
il 4 Apr 2021
Walter Roberson
il 4 Apr 2021
for b = 1 : numel(a)
Caution: length() is not the same as width() . If the array has more rows than columns, then the length() would be the number of rows, same as height()
Brendan Clark
il 4 Apr 2021
0 voti
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!