# could anyone help me how to solve the error in the following code

1 view (last 30 days)
jaah navi on 16 Jul 2021
Commented: jaah navi on 17 Jul 2021
I am having cell array
B=10x1 cell
which contains
10x4 double
10x4 double
10x4 double
10x4 double
10x4 double
10x4 double
10x4 double
10x4 double
10x4 double
10x4 double
I used the following code to convert it
A=cell(size(B));
for i=1:numel(B)
A{i}=splitapply(@(x){x}, 1:numel(B{i}) ,B{i});
disp("YTest{" +i+ "}:"), B{i}
for j=1:numel(A{i})
disp("A{" +i+ "}{"+j+"}:"), A{i}{j}
end
disp ' '
end
##### 2 CommentsShow 1 older commentHide 1 older comment
jaah navi on 16 Jul 2021
Error using splitapply
Group numbers must be a vector of positive integers, and cannot be a sparse vector.
Error in line 3
A{i}=splitapply(@(x){x}, 1:numel(B{i}) ,B{i});

Walter Roberson on 16 Jul 2021
The last parameter to splitapply must be a vector of positive integers, one for each row of input, with the number indicating which group the row belongs to.
It is not clear that your B values are integers. It is clear that B{i} is not a vector.
Perhaps you accidentally exchanged the second and third parameters.
jaah navi on 17 Jul 2021
I want B to convert to A.
B=3x1 cell
2x3 double - [1,1,1 - 1st row
1,2,2]- 2nd row
A=3x1 cell
2x1cell - [1,2,3] 1st row
2x2cell - [1] [2,3] 2nd row