LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-05-2012, 04:31 PM   #1
andiemac
LQ Newbie
 
Registered: Dec 2012
Posts: 1

Rep: Reputation: Disabled
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
 
Old 12-06-2012, 03:46 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by andiemac View Post
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

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 ?"};
So, you have 'numel(questions)' possibilities.

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
and condition it to generate numbers in in the 1 .. numel(questions) range.

Then you use the generated random number as index to 'questions' cell array.
 
Old 12-06-2012, 07:16 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Sergei Steshenko View Post
I don't know Matlab, but I know GNU Octave pretty well.
I know very little of either, but ...

Quote:
If my understanding is correct, your question is not Matlab-specific, it's general programming question.
Except that in Matlab it is usually easier to use arrays for situations where in most programming languages it would be easier to use switch statements and iteration etc.

Quote:
1) you create a cell array with your set of questions:
Sounds like the right idea (though on the details, you're already past my very limited Matlab knowledge).

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:
Then you use any random number generation function, e.g. in Octave in may case it's
No. There the OP was already on the right path. A random permutation is required, not a sequence of independent random selections. Since I didn't read the first post carefully enough, I googled "matlab random permutation" and found the same thing the OP mentioned:
http://www.mathworks.com/help/matlab/ref/randperm.html

Maybe a glance at that will help you improve your answer.

Quote:
Then you use the generated random number as index to 'questions' cell array.
So we assume an array Q of questions, and an array (generated by randperm) of indexes into Q. The OP's question comes down to how to iterate over the index array invoking the questions in that sequence.

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

Last edited by johnsfine; 12-06-2012 at 07:32 AM.
 
Old 12-06-2012, 07:38 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by johnsfine View Post
... A random permutation is required, not a sequence of independent random selections. ...
If each question is required to be asked just once, then yes. If questions can be asked several times, then randomly generated index is OK.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Installed MATLAB in /home/c/Desktop/MATLAB But Cannot ACCESS it hitmen Linux - Newbie 10 09-25-2011 12:11 PM
basic html question - download link to files on my webpage question Davno Linux - Server 5 12-25-2009 07:24 AM
Matlab Distributed Computing Server: Connecting to Matlab client fails OEP Linux - Server 0 12-21-2009 02:18 PM
A question about the installation of the Matlab R2008a on Fedora 8 hxyjlgdx Linux - Software 2 10-31-2008 04:43 AM
Terminal cmd for starting Matlab M-file editor without starting matlab fubzot Linux - Software 2 02-15-2005 06:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration