Azzera filtri
Azzera filtri

Open a picture when an object is clicked.

44 visualizzazioni (ultimi 30 giorni)
David Cole
David Cole il 15 Ago 2024 alle 19:05
Commentato: David Cole il 16 Ago 2024 alle 16:56
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.

Risposta accettata

Rahul
Rahul il 16 Ago 2024 alle 6:02
Modificato: Rahul il 16 Ago 2024 alle 6:04
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 Commenti
David Cole
David Cole il 16 Ago 2024 alle 15:24
Modificato: David Cole il 16 Ago 2024 alle 15:25
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 il 16 Ago 2024 alle 16:56
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

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by