Open a picture when an object is clicked.

2 ビュー (過去 30 日間)
David Cole
David Cole 2024 年 8 月 15 日
コメント済み: David Cole 2024 年 8 月 16 日
I would like to attach an object (or something) next to a block that would open a picture when someone clicks on the object. I don't have a lot of space on my model but I think it would be helpful if someone could click on an object to show a picture of the actual piece of equipment.

採用された回答

Rahul
Rahul 2024 年 8 月 16 日
編集済み: Rahul 2024 年 8 月 16 日
In order to create a clickable field next to your SImulink blocks to open an image, you can use annotations and callbacks to perform this operation:
1. Add an Annotation:
  • Open your Simulink model.
  • Navigate to the area where you want to place the clickable object.
  • Double-click and select Create Annotation from the context menu.
2. Customize the Annotation:
  • Click on the annotation text to edit it. You can enter a label such as "View Image" or an icon representation.
  • Position the annotation next to the block you want it associated with.
3. Set the Callback Function:
  • Right-click on the annotation and select Properties.
  • In the Properties dialog, find the Callback field.
  • Enter a MATLAB command to open the image. For example:
imshow('path_to_your_image.jpg');
  • Make sure the image file is accessible from the MATLAB path or provide the full path to the image.
  • Double-click the annotation text placed next to your block, to open the required image.
For more information regarding annotations and associated callbacks in MATLAB Simulink, kindly refer to the documentation mentioned below:
Best
  2 件のコメント
David Cole
David Cole 2024 年 8 月 16 日
編集済み: David Cole 2024 年 8 月 16 日
Hello Rahul,
imshow worked great and the image opened. Unfortunately, the image opened rotated 90 degrees CCW. I tried to rotate the image but I am getting and error.
ClickFcn code for annotation:
I = imread("C:\Users\Kristy\Desktop\TCR\Substation.jpeg");
J = imrotate(I,90,"bilinear");
imshow(J);
Matlab error:
Error executing callback 'ClickFcn'
Undefined function 'imrotate' for input arguments of type 'string'.
Regards,
David
David Cole
David Cole 2024 年 8 月 16 日
Hello Rahul,
After downloading the image toolkit and running the code again, I was successfully able to rotate the image.
I = imread("C:\Users\Kristy\Desktop\TCR\Reactor.jpeg");
J = imrotate(I,270);
imshow(J)
Thanks,
David

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Model Editing についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by