Can use image name as an argument in an if else statement?

1 回表示 (過去 30 日間)
Suraj Suresh
Suraj Suresh 2017 年 12 月 8 日
コメント済み: Suraj Suresh 2017 年 12 月 8 日
I am a beginner. I have a set of 4 images. The description of each of these images is in separate image files. So is there a way I can use the image names as arguments in an if condition ? For example :-
if selected image = "1.bmp"
Imshow (desc1.jpg)
Else if selected image = "2.bmp"
Imshow (desc2.jpg)
End

回答 (1 件)

ES
ES 2017 年 12 月 8 日
you have to use strcmp to compare strings. And use single quotes in strings.
if strcmp(selectedimage, '1.bmp')
imshow ('desc1.jpg')
elseif strcmp(selectedimage, '2.bmp')
imshow ('desc2.jpg')
End
  1 件のコメント
Suraj Suresh
Suraj Suresh 2017 年 12 月 8 日
Thank you for the reply. The image I am selecting is through the GUI so I am not specifying any path I just have to click on the image to load it. When i tried the code in the above reply it gives me an error saying 'desc1.jpg' is not found. How do I specify the path or where am I supposed to place the image at ?

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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by