Pre-populate boxes in a prompt window?

I have only just in the last month or so learnt how to use MATLAB. I'm currently trying to make a basic GUI for a series of race car dynamics calculations.
I'm using questdlg and inside one case, a prompt. User assigns numbers for variables, and the calculations are completed and results displayed in a msgbox. When button is pressed, user is asked if they want to see results on a line graph, then asked if they want to see some other results on a bar chart.
Finally user is asked if they want to change any values. If yes is selected, code steps back to the start of the while loop where the prompt box is created and opened.
I want the boxes in this prompt to contain the numbers they original input, so changing just one and seeing the change in results is easy.
Can I do this? If so, how? I have avoided GUIDE as I want a very short simple script (240 lines inc. comments currently)

 Accepted Answer

I would consider using the listdlg function the second time. It would allow the user to select the variable to be changed, then you could go to perhaps inputdlg to change it, and then continue with your simulation.
There are likely more sophisticated ways to design GUIs to do what you want, but I also generally use the simple ones, since I’m the only one using my applications at present. (If necessary, I would develop a more friendly GUI user interface for anything I submitted to the File Exchange. Just now, none of them need GUIs.)

11 Comments

Matt
Matt on 25 Nov 2015
Edited: Matt on 25 Nov 2015
I have used inputdlg actually the first time around with a prompt. My mistake there...
So - I'm trying listdlg but i'm at a loss as to how to list my variables in the window.
I think I could probably figure the rest out if I could get that far!
I'm thinking if you chose to adjust mass, for example, set a new variable called 'adjust' to contain 'mass'. As you say I could then open another inputdlg box asking what to change the value to, then assigning the new input to the original 'mass' variable.
This could be incorporated into a while loop around the calculations and graphing.
I guess I could just input the variables into the listdlg code manually actually - my variables for the equations don't get added/removed of course.
I have a basic version programmed now, but if I pick 'Mass', edit_selection becomes 1.
How can I program it so that 'Mass' is stored in a variable called 'Edit_Selection' please?
% Choice for continuing through UI again
choice4 = questdlg('Would you like to change any parameter values?',...
'How to Proceed?', 'Yes','No, Quit', 'No, Quit');
switch choice4
case 'No, Quit'
close all
return
case 'Yes'
Edit_Selection = listdlg('PromptString', 'Select variable to edit & press OK',...
'SelectionMode','single',...
'ListString',{'Mass','Lateral Accel'});
I was thinking you could save the original questions as a cell array of strings, present them individually in inputdlg, save the results, then concatenate the questions and the original numeric responses to create a list for listdlg the second time around. The index returned by listdlg would be all you would need to present the correct choide for inputdlg. Then save the new values and repeat until the user wants to go do something else.
Matt
Matt on 26 Nov 2015
Edited: Matt on 26 Nov 2015
I managed to do it prior to your comment in the end but in a roundabout way - due to lack of ability really, but given I've only spent a few evenings learning to do what I have, I think I am doing well.
Your method would be much more efficient I think - thanks. I will give it a try when I find the time. That is what I wanted to do, but wasn't sure how.
I've sent you a message also...
My pleasure. I got your message, downloaded your .m-file, and will look at your code later.
I would still experiment with GUIDE, especially if you want to impress your potential employers with your MATLAB skills. (You will also demonstrate how well you can function when chronically sleep-deprived!)
I certainly will. I'd like a UI which shows the effect of adjustment of variables better.
Please message me with your thoughts on my code. I'm fairly happy with it until the editing of variables near the end, which is a bodge really, but it was the only way I knew how to get the functionality! Too many if statements... surely the better way is storing everything in an array but i've got no idea how to implement it.
The above suggestion by Geoff Hayes worked very well for your interest. I think it's made the GUI a bit more fluid as opposed to the listdlg solution I had managed to bodge to make it work (the version sent to you).
I’m happy you got that sorted. I use inputdlg frequently with the 'Default' option, but wasn’t clear on what you wanted, or that it would work in your application. I’ll stop working on it unless you have other questions.
Also, dropbox and other third-party applications aren’t the best ways to attach code, figures, data, and such. Use the ‘paperclip’ or ‘staple’ icon above the text window for code and data files, and the brown-framed green landscape picture icon for figures instead.
I sort of took yesterday off. It was the U.S. Thanksgiving Day holiday. We all get mildly inebriated while we roast a Theropod dinosaur stuffed with breadcrumbs. Some of us go raid retail establishments that should be closed for the holiday to buy things we don’t need with money we don’t have.
Thanks - I hadn't noticed the paperclip - doh!
What I achieved with the further inputdlg capability of pre-filling the cells I didn't know you could do, but is exactly what I had hope to achieve. I'll send you the code if you care to see... Any suggestions you had looking at it before would be appreciated still - i'm eager to learn.
Hope you had a good Thanksgiving!
No worries. It’s documented in the Help tab at the top of the page, but not obvious unless you look for it. (The ‘Help’ icon above the text window only deals with markup.)
I would like to see your code when you get it working to your satisfaction. We’re all learning here. Please document it extensively with comments so that I and others (and you if you want to modify it later) can easily understand how it works. I can also learn something about vehicle dynamics.
I did. Thank you!
I had one other thought with respect or your prospective employer. If they’re doing everything with Excel and you know and are proficient with MATLAB, you’ll walk on water there! You’ll have to convince them to buy MATLAB and the necessary toolboxes and Simulink, so also have all the information as to what is necessary and the costs and licensing options at hand when you interview. Contact MathWorks directly and ask them for the details.
And explore the xlsread and related functions when you have the opportunity. Looks as though you’ll be using them often!

Sign in to comment.

More Answers (1)

Don't be afraid of GUIDE. It's not that hard and can make some things easier. Perhaps you'd like to get started with this easy-to-use generic framework. http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component
Description This GUI will help the novice user get up to speed very quickly on using GUI-based applications. Everything is laid out in a very simple Step 1, Step 2, Step 3, etc. layout. It is a very good starting point for a typical image analysis application. This application uses GUIDE to do the user interface design, and has most of the basic controls such as buttons, listboxes, checkboxes, radio buttons, scrollbars, etc. It allows the user to select a folder of images, select one or more images and display them, to select a series of options, and to individually or batch process one or more images. The user can

4 Comments

Thanks, I will try that GUIDE example.
I'm not afraid of it as such - this is just a piece of coursework that I have spent far too much time on in order to do much more than required to impress a potential employer.
I will experiment with GUIDE once this is submitted, but don't want to spend much longer on this piece of work! The way I have done it shows more programming ability too I think?
If your objective is to impress a potential employer, PULL OUT ALL THE STOPS! Go for the GUIDE option, both because you’ll learn useful skills and will show your potential employer you’re willing to learn and attempt new things. Make your code original (all yours), clean, efficient, reasonably robust, and fun for the employer to use when the employer uses it. It could be used by several people, all of whom may have a say in whether to hire you and determine your compensation, and some of whom may have significant experience with MATLAB. And be confident and professional, not obsequious, in your programming and all other interactions with your potential employer.
I’m certain others will have additional ideas, probably amending mine in some respects.
GOOD LUCK!
You haven't shown much - probably not the full code. But what little I see, as an employer, is simple, primitive code. I see someone who just wanted to do something quick and dirty to get an answer but really wasn't interested in writing professional code worthy of selling to the general public or my customers. Could you write a professional program - something with the GUI sophistication of Word, Excel, Powerpoint, or Photoshop? Who know - maybe you can and maybe you can't. I would not be able to determine that from the snippet you gave. I certainly would not be impressed at that code, at least not enough to hire you based on your ability to write robust professional looking software - there's just nothing there to demonstrate that. Graphic designers, artists, and fashion designers have portfolios of their work - illustrations of what they've designed. Do you have that? I'd maybe be impressed if you showed me 20 screenshots of GUIs of different programs that you designed. Or if you could tell me that you have 6,000 users of your application, or that you have 8 applications for sale to the general public - something like that.
When I hired an image processing Ph.D. we looked at dozens of resumes, telephone interviewed about a dozen, and brought in 3 or 4, and ultimately hired one. They all said they knew MATLAB. One even said that he taught MATLAB. So I asked them all a simple question. I said I had a white substrate with dark stain on it and different images had different amounts of stain cleared away, so their area fractions were different. I told them I wanted to know the area fraction of white and dark, and I had good control over the lighting. I asked them how they would do it in MATLAB. This is about as basic as you can get. You'd be surprised how many or them could not solve the problem. Some of them didn't even know about regionprops() - which is THE number one main function of the entire Image Processing Toolbox. Most of them came up with wrong algorithms - nonsense like graythresh(), etc. And these were Ph.D.s who were supposed to be MATLAB experts. Only one got the right answer and that was with me throwing a few hints his way.
Matt
Matt on 26 Nov 2015
Edited: Matt on 26 Nov 2015
Thanks for your advice. I have it working now, but it would be more efficient with everything stored in an array I could refer the code to various cells (values and names) at different times.
It is a university piece of coursework, where I have met the requirements and started from no MATLAB experience. The employer I want to impress is a small engineering outfit who currently use Excel, and have little/no experience with MATLAB, but carry out similar calculations within Excel.
I fully understand and appreciate what you are saying but I am not going for a job as a programmer, but instead a vehicle dynamics engineer.
In time I will play with GUIDE and look to make this script more efficient, but for now it works as it needs to, and owes me too much time!

Sign in to comment.

Categories

Asked:

on 24 Nov 2015

Commented:

on 27 Nov 2015

Community Treasure Hunt

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

Start Hunting!