Can anyone explain from the third line till the end of below code..??

1 回表示 (過去 30 日間)
Sombaran Gupta
Sombaran Gupta 2015 年 4 月 13 日
編集済み: Thorsten 2015 年 4 月 14 日
a=imread('kmeans.jpg');
imshow(255-rgb2gray(a));
b=reshape(double(255-rgb2gray(a)),[],1);
[idx,c]=kmeans(b,2,'emptyaction','singleton');
Fin_a=reshape(idx,[size(rgb2gray(a))]);
[ind1, ind2]=find(Fin_a(:,:)==2);
[ind3, ind4]=find(Fin_a(:,:)==1);
figure();
imshow(255-rgb2gray(a));
hold on
if(length(ind1)<length(ind3))
scatter(ind2,ind1,'g');
else
scatter(ind4,ind3,'g');a
end
  1 件のコメント
Thorsten
Thorsten 2015 年 4 月 14 日
編集済み: Thorsten 2015 年 4 月 14 日
Why don't you just run the code line by line and use doc and read what the functions are doing? And then ask again if you can't figure out particular parts/lines.

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

回答 (1 件)

Chris McComb
Chris McComb 2015 年 4 月 13 日
The third line from the end contains only the word 'else'. This is typical syntax for the if control structure. In the example, if length(ind1)<length(ind3), the program executes
scatter(ind2,ind1,'g');
However, if length(ind1)<length(ind3) is not true, the program will try to execute:
scatter(ind4,ind3,'g');a
and exit with an error, because the line ends with an 'a' character.
  2 件のコメント
John D'Errico
John D'Errico 2015 年 4 月 14 日
I think the question was asking for an explanation starting from line 3 until the end, not the third line from the end.
Sombaran Gupta
Sombaran Gupta 2015 年 4 月 14 日
yes from the third line till the end.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by