Assign output a name?

6 ビュー (過去 30 日間)
Chelsea
Chelsea 2014 年 11 月 5 日
コメント済み: Orion 2014 年 11 月 5 日
Hi,
I am working on something where I have a vector of image files, and I get Matlab to shuffle them and give me one. I would like to take the output answer (the random image) and display it. How do I assign the output a name? I tried ans=RandImage, but that didn't work. Here's the code I have that leads up to this. Thanks!
Images = {'11a.bmp';'12b.bmp';'12c.bmp'; etc. etc.}
% Shuffle images
Images=Shuffle(Images)
Images{ceil(rand(1)*length(Images))}
%% Here's where Matlab gives me an image %%
ans = 11w.bmp
^ I would like to take this to somehow plug the output into the imread command.
Thanks!

採用された回答

Orion
Orion 2014 年 11 月 5 日
編集済み: Orion 2014 年 11 月 5 日
Hi, for what I see, you need to do :
Images = {'11a.bmp';'12b.bmp';'12c.bmp'}; % list of images
RandomNumber = randi([1 length(Images)]); % random number between 1 and the number of images
image(imread(Images{RandomNumber)) % display the random image.
  2 件のコメント
Chelsea
Chelsea 2014 年 11 月 5 日
編集済み: Chelsea 2014 年 11 月 5 日
Thanks for your response! I've figured it out :)
Orion
Orion 2014 年 11 月 5 日
just create an output variable.
Images = {'11a.bmp';'12b.bmp';'12c.bmp'; etc. etc.}
% Shuffle images
Images=Shuffle(Images)
MyRandomImage = Images{ceil(rand(1)*length(Images))};
then use
image(imread(MyRandomImage))
One Important thing : ans is a key word in matlab, try to never use it, otherwise you're gonna have some trouble later.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by