ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

Click Here to receive this Complete Guide absolutely free.

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');

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:

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

LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.