Could anyone help me how to group into 4 sets.

I ma having a matrix
A=[2 3 1 4 5 6]
i used the command
NN = num2cell(num2cell(A),2)
,which gives the following result
{2} {3} {1} {4} {5} {6}
If i use the command
NN= num2cell(num2cell(A,2),2)
it gives the following result
{1 2 3 4 5 6}
Could anyone help me how to get the result in the following manner
{2 3} {1 4 5} {6}

1 Kommentar

What if criterion of grouping?
Why
{2 3} {1 4 5} {6}
And not
{2 3} {1 4 5 6}

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Raj
Raj am 20 Sep. 2019

0 Stimmen

Use this:
NN = mat2cell(A,[1],[2,3,1])

4 Kommentare

jaah navi
jaah navi am 22 Sep. 2019
When A=[2 3 1 4 5 6] the above command executes and gives me the result.
I tried the following command with A=[1 2 3 4;
2 3 1 4;
1 4 2 3]
but it gives error stating Input arguments, D1 through D2, must sum to each dimension of the input
matrix size, [3 4].'
Could you please help me on it.
madhan ravi
madhan ravi am 22 Sep. 2019
Bearbeitet: madhan ravi am 22 Sep. 2019
Raj seemed to have answered our original question. What is your desired result? Didn’t you figure it out of how to use mat2cell() still (after 10 questions)?
Stephen23
Stephen23 am 22 Sep. 2019
Bearbeitet: Stephen23 am 22 Sep. 2019
jaah navi: you have been using MATLAB for more than two years.
During that time you have asked us every ten minutes to solve basic problems for you, most of which you could solve yourself by reading the documentation.
Rarely do you make any attempt to understand what an error message is telling you.
Rather than relying on us to write your very basic code for you, perhaps you should start reading documentation, trying examples, looking at FEX submissions, debugging, and doing it yourself. Note that this is in your interest because you would actually make progress much faster than you are now.
Your current approach to writing code (relying on other people to write every step of your algorithm and relying on other people debugging every tiny error message) is, in the long term, not efficient.
darova
darova am 22 Sep. 2019
+1

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 20 Sep. 2019

Bearbeitet:

am 22 Sep. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by