Accessing elements from 2d array using for loop

8 ビュー (過去 30 日間)
Meenal Shah
Meenal Shah 2020 年 5 月 11 日
コメント済み: Ameer Hamza 2020 年 5 月 11 日
I am using MATLAB for image processing
I have made gradmag as an outline of brain MRI scan and fgm4 is only the tumor region of the MRI.
Both are 2d arrays.
The following code, however, gives error:
G1 = zeros(200,200);
for i=1:200
for j=1:200
if((gradmag[i][j]>0) && fgm4[i][j]>0)
G1[i][j]=255;
end
end
end
figure
imshow(G1); title("Outline");
The error:
Error: File: test1.m Line: 106 Column: 20
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check
for mismatched delimiters.
Line 106 refers to the if statement

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 11 日
編集済み: Ameer Hamza 2020 年 5 月 11 日
In MATLAB parenthesis are used for indexing, So change your code lines to
if((gradmag(i,j)>0) && fgm4(i,j)>0)
and
G1(i,j)=255;
You can also take this course: https://www.mathworks.com/learn/tutorials/matlab-onramp.html to learn basics about MATLAB.
  2 件のコメント
Meenal Shah
Meenal Shah 2020 年 5 月 11 日
Thank you so much!!!
Ameer Hamza
Ameer Hamza 2020 年 5 月 11 日
I am glad to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by