How to truncate empty cells from a cell array?
I have a cell with some data that has empty cells in the array. Please disregard how ‘number_cell’ is made, it’s purely for example so readers have something to work with. In reality, I am receiving data that has empty rows and columns. I have no control over that.
number_cell = cell(4,4);
number_cell(1,1) = num2cell(1);
number_cell(1,2) = num2cell(2);
number_cell(1,4) = num2cell(3);
number_cell(2,1) = num2cell(7);
number_cell(2,2) = num2cell(8);
number_cell(2,4) = num2cell(9);
number_cell(4,1) = num2cell(14);
number_cell(4,2) = num2cell(15);
number_cell(4,4) = num2cell(17);
updated_cell = number_cell(~cellfun(‘isempty’,number_cell)) ; %I’ve tried playing with this to no avail.
The issue I have is that the 3rd column and 3rd row have empty cell values. What I need to do is truncate this 4×4 cell of the one row and column of empty cells so the output is a 3×3 matrix.
Here’s what I start with:
And here’s my desired output:
What do I need to change in my code?
Thanks for reading!I have a cell with some data that has empty cells in the array. Please disregard how ‘number_cell’ is made, it’s purely for example so readers have something to work with. In reality, I am receiving data that has empty rows and columns. I have no control over that.
number_cell = cell(4,4);
number_cell(1,1) = num2cell(1);
number_cell(1,2) = num2cell(2);
number_cell(1,4) = num2cell(3);
number_cell(2,1) = num2cell(7);
number_cell(2,2) = num2cell(8);
number_cell(2,4) = num2cell(9);
number_cell(4,1) = num2cell(14);
number_cell(4,2) = num2cell(15);
number_cell(4,4) = num2cell(17);
updated_cell = number_cell(~cellfun(‘isempty’,number_cell)) ; %I’ve tried playing with this to no avail.
The issue I have is that the 3rd column and 3rd row have empty cell values. What I need to do is truncate this 4×4 cell of the one row and column of empty cells so the output is a 3×3 matrix.
Here’s what I start with:
And here’s my desired output:
What do I need to change in my code?
Thanks for reading! I have a cell with some data that has empty cells in the array. Please disregard how ‘number_cell’ is made, it’s purely for example so readers have something to work with. In reality, I am receiving data that has empty rows and columns. I have no control over that.
number_cell = cell(4,4);
number_cell(1,1) = num2cell(1);
number_cell(1,2) = num2cell(2);
number_cell(1,4) = num2cell(3);
number_cell(2,1) = num2cell(7);
number_cell(2,2) = num2cell(8);
number_cell(2,4) = num2cell(9);
number_cell(4,1) = num2cell(14);
number_cell(4,2) = num2cell(15);
number_cell(4,4) = num2cell(17);
updated_cell = number_cell(~cellfun(‘isempty’,number_cell)) ; %I’ve tried playing with this to no avail.
The issue I have is that the 3rd column and 3rd row have empty cell values. What I need to do is truncate this 4×4 cell of the one row and column of empty cells so the output is a 3×3 matrix.
Here’s what I start with:
And here’s my desired output:
What do I need to change in my code?
Thanks for reading! cell, truncate, matlab MATLAB Answers — New Questions









