Could anyone help me to solve the issue.

I am having matrix
A=[1 2;
2 3;
2 4]
when i use the command
NN = num2cell(num2cell(A),2)
partdisp(NN)
i am getting the result as
NN =
{1x2 cell}
{1x2 cell}
{1x2 cell}
The formation of clusters :
{1} {2}
{2} {3}
{2} {4}
but i need to have the result in the following manner
NN =
{1x1 cell}
{1x1 cell}
{1x1 cell}
The formation of clusters :
{1 2}
{2 3}
{2 4}
could anyone please help me on it.

 Accepted Answer

madhan ravi
madhan ravi on 13 Sep 2019
Edited: madhan ravi on 13 Sep 2019
NN = num2cell(num2cell(A,2),2)

4 Comments

i am having the matrix
A =[ 2 3 4 1 5 6 7 ;
1 4 3 2 5 6 7 ;
2 4 3 1 5 6 7;
3 4 1 2 5 6 7]
If i use the command
NN = num2cell(num2cell(A,2),2)
all are getting grouped together
NN ={1x1 cell}
{1x1 cell}
{1x1 cell}
{1x1 cell}
if i use the command NN = num2cell(num2cell(A),2) all are separate
NN ={1x7 cell}
{1x7 cell}
{1x7 cell}
{1x7 cell}
Could you help me how it can be done for the criteria {2 3}{4 1 5} {6} {7}
to have first two numbers present in first row are grouped together,followed by next three numbers grouped together ,followed by next one number alone ,followed by the last number alone
That question is different from what you asked originally.
ok.But is there any other way to have random combinations like {2 3}{4 1 5} {6} {7} other than { 2 3 4 1 5 6 7} or {2} {3} {4} {1} {5} {6} {7}.
mat2cell(A,[1,1,1],[2,3,1,1]) % see the documentation and learn how to use it

Sign in to comment.

More Answers (1)

For your case
NN = mat2cell(A,[1 1 1],2)
A bit more general
NN = mat2cell(A,ones(size(A,1),1),size(A,2))

5 Comments

Isn’t that what Rik posted earlier to this answer?
The time difference is a few minutes (seconds?): I haven't seen Rik's answer before posting.
I believe it was about 5 minutes, which happens a lot if you open a recent question and open a few tabs at once to answer them in a batch. One time there were already 4 answers (3 of which way better than mine) by the time I had found a working solution.
Not my case. Just running the code before posting
Yeah, even just opening a question and typing your answer can take long enough that when it's posted there are 2 or 3 other answers too. It's perfectly fine though.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!