MATLAB Answers

Display seven-segment

90 views (last 30 days)
Suk King Chia
Suk King Chia on 8 May 2020
Edited: Image Analyst on 4 Sep 2020
I wish to design a GUI to display seven-segment as shown as the figure below.
But I want to ask user to enter their input between range 0-9 in the command window but not in GUI. Which mean i will receive the input from command window and display it in the GUI. What code can make it work?

  0 Comments

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 8 May 2020
Create a 10 x 7 logical array, one row for each digit, with each row being a list of values of which segments should be lit for the corresponding digit. You can use any order of segments that is consistent. For example the 6th row, for the digit 5, could be [true true false true false true true] .
Then when you have the user input and have verified that the input is a non-negative integer with a single digit, then take the input, add 1, and use that as the row index to get out the segment information. Then use that information to set the segments appropriately.
Or you could define it as an array of color letters, such as 'bbkbkbb' that you use to set the colors for the segment.

  11 Comments

Show 8 older comments
Rik
Rik on 9 May 2020
It might not be my place to criticize you teacher, but all these requirements seem very odd to me.
Walter Roberson
Walter Roberson on 9 May 2020
"Create a graphical interface using a MATLAB program named HDTask2.m to verify your digital circuit design, which must also satisfy the following programming requirements:"
That does NOT require that you use guide.
Suk King Chia
Suk King Chia on 9 May 2020
Cause my lecturer mentioned use guide before, but I will ask my lecturer is it compulsory to use guide or I can do this task in different way. Really appreciate ur guys help!

Sign in to comment.


Image Analyst
Image Analyst on 9 May 2020
Edited: Image Analyst on 9 May 2020
I think the simplest way is to just have 10 images. Then all you have to do is to convert the user input into a filename string and display the proper image. I'd have 7 edit text boxes where the user can type in a 0 or 1. In the callback for that edit field, you call a function to read all 7 edit fields and get the filename and read in and display the proper image. For example in each edit field's callback you'd have
function edtDigit1_Callback(hObject, eventdata, handles)
DecodeDigitsAndDisplayImage(handles);
Same for all the other 6 edit fields. Or, if you have to, get the 7 strings from the command window.
Now the DecodeDigitsAndDisplayImage() function would look like
function DecodeDigitsAndDisplayImage(handles)
% Get digits from edit fields on GUI.
digit1 = handles.edtDigit1.String;
digit2 = handles.edtDigit2.String;
% etc. for all 7 digits.
% Or, if you have to, get the 7 strings from the command window.
ourDigit = [digit1, digit2, digit3, digit4, digit5, digit6, digit7]
% Read in proper image, one of 10 or 11 (if including all off condition) images.
baseFileName = sprintf('%s.png', ourDigit); % Assuming it's a PNG image file that you have.
fullFileName = fullfile(pwd, baseFileName) % For example 'c:\test\0010110.png'
theImage = imread(fullFileName);
% Display that image.
imshow(theImage, []);
You don't really even need GUIDE for this if you're not using edit fields. If you're just getting 0s and 1s from the command window you could just get those digits somehow, like from input() or inputdlg(), and then call the function passing in those strings:
function DecodeDigitsAndDisplayImage(digit1, digit2, digit3, digit4, digit5, digit6, digit7)
% Build the filename from the 7 strings gotten from the command window.
ourDigit = [digit1, digit2, digit3, digit4, digit5, digit6, digit7]
% Read in proper image, one of 10 or 11 (if including all off condition) images.
baseFileName = sprintf('%s.png', ourDigit); % Assuming it's a PNG image file that you have.
fullFileName = fullfile(pwd, baseFileName) % For example 'C:\test\0010110.png'
theImage = imread(fullFileName);
% Display that image.
imshow(theImage, []);
Again, the 10 or 11 images have been computed in advance. You already have, and showed us, the 5 so you just need to fill or clear the other segments and save the images. If you don't want to save the images in advance, you could just have a function where you create the digits on the fly, though it's a bit more involved.

  3 Comments

Suk King Chia
Suk King Chia on 9 May 2020
Thanks a lot! I will try this out!
michelle papas
michelle papas on 4 Sep 2020
Hi did you get this program to work?
Image Analyst
Image Analyst on 4 Sep 2020
Possibly not since he didn't accept my answer. But that doesn't mean you can't do it. Give it a try. Do you have the 10 images yet? If not, a few minutes in Photoshop and you'll have them created. I'm attaching a set here.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!