Dynamically changing values displayed on GUI

Hi, I am well conversant with making basic MATLAB GUI. However, I want some specialized features as follows: 'As a user slides the slider, I want a bucket to get filled with water'. Hence, if the user slides to 50% of total slider value, the bucket must dynamically change the level of water and show the bucket to be half full.
Any suggestions to accomplish this and integrate such dynamic objects on GUI screen?

7 comentarios

Walter Roberson
Walter Roberson el 4 de Mayo de 2012
What shape is the bucket, and what representation should be used for the water? Is a line at the water level enough, or does it need to be a nice water-blue filling inside of an irregular bucket shape? Are ripples in the water mandatory? Refraction of the light at the air-water boundary? Fish in the water? Sediment has to swirl around? The occasional rubber ducky?
Jan
Jan el 4 de Mayo de 2012
This is a vague question yet. What exactly is "a bucket"? And how should the filling look like? What have you tried so far and which problems have occurred?
Walter Roberson
Walter Roberson el 4 de Mayo de 2012
Me? Well, I did some research, but the smallest rubber-duck icon I could find was 32 pixels by 32 pixels. But I need an opinion on that: is the 17 x 17 pixel duck at The World's Smallest Web-Site a rubber duck or not? http://www.guimp.com/sc_korsun_duck.html
ANUBHAV SINHA
ANUBHAV SINHA el 4 de Mayo de 2012
Hi Walter...sorry if the question is not clear. In simplest words...I need the visual that looks like a bucket in which blue water is filled and whose level changes as the slider is changed. I do not want any fancy features--no refraction, no fish, no rubber duck, no girls in water... I jus want a simple blue space filling a container.
Thanks
ANUBHAV SINHA
ANUBHAV SINHA el 4 de Mayo de 2012
@Jan - I hope the question is clear now. Please suggest if you have something in mind
Walter Roberson
Walter Roberson el 5 de Mayo de 2012
How realistic does the bucket have to look? Like is a plain rectangle good enough? A trapazoid? Does it have to look like a traditional wooden bucket like http://4.bp.blogspot.com/-YciJsaGk2oI/TWsxVFG2leI/AAAAAAAAAEk/3qlIXRAyv3U/s1600/WoodenBucket3DModelZoom.jpg
ANUBHAV SINHA
ANUBHAV SINHA el 5 de Mayo de 2012
@Walter: Bucket= rectangle; Water=blue color. No fancy.
Thanks

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 5 de Mayo de 2012
Here's the demo code using patch():
workspace;
fontSize = 20;
% Ask user for a number.
defaultValue = 45;
titleBar = 'Enter a value';
userPrompt = 'Enter the percent full';
caUserInput = inputdlg(userPrompt, userPrompt, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
usersValue = str2num(cell2mat(caUserInput));
% Check for a valid number.
if isempty(usersValue)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
usersValue = defaultValue;
message = sprintf('I said it had to be an number.\nI will use %d and continue.', usersValue);
uiwait(warndlg(message));
end
%======== KEY CODE RIGHT HERE ====================
X = [0 1 1 0];
Y = [0 0 usersValue usersValue];
C = [.3 .5 .8];
patch(X,Y,C)
% Make the plot look nice.
grid on;
ylim([0 100]);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
caption = sprintf('Bucket filled %g%%with water', usersValue);
title(caption, 'FontSize', fontSize);
ylabel('Percent full of water', 'FontSize', fontSize);

1 comentario

ANUBHAV SINHA
ANUBHAV SINHA el 8 de Mayo de 2012
Thanks a lot!!! It works.
If I intend to put 4 such graphs on the same plot then which part of code should I be changing and what command be using?

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 4 de Mayo de 2012
How about you take photos of a bucket with 100 different levels of water. Then you set the slider to go from 0-100. When the user slides the slider, you get the number, and recall the corresponding image and display it?
sliderValue = int32(get(handles.slider, 'Value'));
baseFileName = sprintf(image_%d.PNG', sliderValue);
fullFileName = fullfile(folder, baseFileName);
if exists(fullFileName , 'file')
imshow(fullFileName);
end
Or else use patch() and do it on a computer graphics simulated bucket.

2 comentarios

ANUBHAV SINHA
ANUBHAV SINHA el 4 de Mayo de 2012
Gr8 to have the popular ImageAnalyst answering my question. I have followed many of your answers/postings from time to time. Thanks for answering.
Ya that idea did strike me but I find it very cumbersome but maybe I have upto 1000 levels to fill the water in the container. So I feel it is tiresome. Can you suggest some automatic technique?
Image Analyst
Image Analyst el 5 de Mayo de 2012
To see 1000 levels, at one row of pixels on your monitor, you'd need at least 1000 lines on your monitor. That doesn't leave much space for the rest of your GUI. But anyway, you can use patch. See my demo code in another Answer here.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by