Creating a row vector of combinations?
Show older comments
I have a row vector that 1 by 4. And I know that the minimum and maximum values of the elements in this vector to be -15 and 15. How can I make a matrix that is N by 4 that contains all possible combinations of ALL values?
Let me given an example: min = -15, max = 15, so the result of the code should be a matrix that is N by 4 that will look something like this
A = [[-15,0,0,0];[-14,0,0,0];[-13,0,0,0];[-12,0,0,0];[-11,0,0,0];[-10,0,0,0];[-9,0,0,0];....and so on until the final value vector to be[15,15,15,15]];
Accepted Answer
More Answers (1)
One simple aprpoach is to download this FEX submission:
but you will need plenty of memory:
V = -3:3
X = combinator(numel(V),4,'p','r');
M = V(X)
7 Comments
Dyuman Joshi
on 25 Jan 2023
Does MATLAB Answers (and MATLAB Live Editor by extension) have the ability to directly run FEx functions/files?
Stephen23
on 25 Jan 2023
"Does MATLAB Answers (and MATLAB Live Editor by extension) have the ability to directly run FEx functions/files?"
Not as far as I am aware. You might be able to copy them automatically, if you know the URL.
Ali Almakhmari
on 25 Jan 2023
Dyuman Joshi
on 25 Jan 2023
"You might be able to copy them automatically, if you know the URL."
What do you mean by copy them? Also, how did you run the function?
Davide Masiello
on 25 Jan 2023
I have the same question.
"What do you mean by copy them?"
Perhaps COPYFILE or one of the WEB* or URL* functions lets you copy from the FEX location to the Answers environment, from whence you could run it. Go and read the documentation and do some experiments. I can't help you with this, I have never tried.
"Also, how did you run the function?"
I downloaded it from FEX, uploaded it here, ran the code, then (out of respect for the submitter's license conditions) deleted the function before submitting my answer. You can delete uploaded files by clicking on the little red "x":
Dyuman Joshi
on 27 Jan 2023
Okay, I'll try it. Thanks for replying.
"I downloaded it from FEX, uploaded it here, ran the code, then (out of respect for the submitter's license conditions) deleted the function before submitting my answer."
Fair enough.
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!