image changing gui matlab

1 次查看(过去 30 天)
Fco. Javier Rodríguez Mira
Hi, I´d like to make a code that displays an image in a gui from a vector. I mean, I´ve got a vector that has the values 0,1,2 and I need to display in a gui an image depend on the value. I´ve got no idea to make this. Thank you.
  2 个评论
Geoff Hayes
Geoff Hayes 2020-5-26
What are the dimensions of your vector? How are these three numbers (or are there more?) mapped to colours?
Fco. Javier Rodríguez Mira
Hi, thank you for your response. The vector dimensions are 1x34740. It only has 0,1, 2 and 3 and what I need is: when I have a 0 I need to display an arm image(brazo22) in repose, when is 1 I need to display an arm image in flexion(brazo11) ,when is 2 I need to display an arm image in extension (brazo33) and when it has a 3 I need to display the same image as when It's in repose(brazo22). I´ll attach a zip that contains the gui(poyecto.fig) the function of the gui(proyecto.m), the images of the arm, another function that is the function where I extracted the code for the gui(SolucionP2_eje2.m) and a data archive(EMG 2 channel Wrist Flex_Ext_Raw.mat). In both of the .m archives is a vector called "salida" that is the vector with the 3 values. A brief summary of what I need is: I have a data archive that I have processed and then make a vector "salida" for the values in the previous data. Now I need to make a gui for that 3 values to display an image deppend on the value. Sorry for my bad english but I'm trying the best. Thank you.

请先登录,再进行评论。

回答(1 个)

Geoff Hayes
Geoff Hayes 2020-5-27
So once you have created the salida array you need to determine which GUI action will invoke the process to display all the images one after the other. Let's assume that you have a pushbutton to do this. In the callback, you would place all of your code (that is right now in the OpeningFcn) to create the salida array, load the three images, and then cycle through each value in the array. Something like
image0 = imread('brazo22.jpg');
image1 = imread('brazo11.jpg');
image2 = imread('brazo33.jpg');
for k = 1:length(salida)
value = salida(k);
if value == 0 || value == 3
imshow(image0);
elseif value == 1
imshow(image1);
elseif value == 2
imshow(image2);
else
fprintf('error - invalid value: %d!\n', value)
end
pause(1.0); % <---- pause for one second
end
You can use a switch statement instead of the if/elseif if you'd rather. So we get the value of the kth element of the array, show the appropriate image (in the axes of your GUI), pause for one second (you can change this) and then move to the next element.
  2 个评论
Fco. Javier Rodríguez Mira
Thank you very much, but I need the loop to be a little bit faster like a millisecond because there is a lot of elements in salida. Could that be possible?
Geoff Hayes
Geoff Hayes 2020-5-28
You can try changing the input to pause to
pause(0.001);
and see what happens.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by