Very basic question in Matlab
Let me start by saying this is probably going to be super basic for most of you. My goal is to make GUI that displays multiple questions separately in a random order using randperm. I've got my initial question popping up just fine, but I'm not sure how to use randperm for automatically moving on to the next random question, at all. The only time I've used randperm is working with numbers in a matrix. One of my question's codes is below:
function Noteven() f = figure handles.questionOne = uicontrol('style','text','position',[400 200 150 60], ... 'string', 'Which number is not even?', 'fontsize', 16);% uicontrol('style','popupmenu','string','Choose|3|2|1') if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end |
Quote:
I don't know Matlab, but I know GNU Octave pretty well. It doesn't have a GUI though, but I think GUI issues is not you problem, you problem is: "I'm not sure how to use randperm for automatically moving on to the next random question, at all". If my understanding is correct, your question is not Matlab-specific, it's general programming question. The solution is along the following lines: 1) you create a cell array with your set of questions: Code:
questions = {"goo ?", "bar ?", "d\'oh !?", "dah ?", "who ?", "what ?"}; Then you use any random number generation function, e.g. in Octave in may case it's Code:
`random' is a function from the file /mnt/sdb8/sergei/AFSWD_debug/20121021/octave-3.6.2/share/octave/packages/statistics-1.1.3/random.m Then you use the generated random number as index to 'questions' cell array. |
Quote:
Quote:
Quote:
If I understood the OP, each "question" has been constructed as a separate function that must be called to ask the question. The question is not represented as simply some text. Andiemac, please correct me if I misunderstood that. If I'm right so far, that array of questions must be an array of something that acts like function pointers. I have no clue how to do that in Matlab, but I expect it can be done and I expect it is the same in Octave. Quote:
http://www.mathworks.com/help/matlab/ref/randperm.html Maybe a glance at that will help you improve your answer. Quote:
If Matlab doesn't support something that acts like an array of function pointers, then you probably need to do that the crude way with a switch statement. Edit: A little help from google told me that Matlab function pointers are called function handles and the way to work with an array of them is documented at the end of the page at http://www.mathworks.com/help/matlab...on_handle.html |
Quote:
|
All times are GMT -5. The time now is 03:45 AM. |