Delete Data from a Cell Array

5 views (last 30 days)
Hi,
I have an array called AA that contains 36 cells ( inside each cell there is another 36 matrix each matrix contains 36 Rows and 30 Columns ). as shown in the attached image
I have written For Loop in order to delete from each Cell the whole data of the first Column and store the new array Called AA1 but it doesn't work
for mm1=1:36
AA2=AA;
AA2{mm1}{mm1}=[];
end
For Example: in the first iteration, I'd like to remove AA1{1}{1} in the second iteration, I'd like to remove AA1{2}{2} and so on
really appreciate any help. Kind Regards.
  2 Comments
neamah al-naffakh
neamah al-naffakh on 14 Jan 2017
thank you so much, but i really dont know how to do it ? i am new to MATLAB
do you want me to attach me code to have a look on it please?

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 14 Jan 2017
Edited: Guillaume on 14 Jan 2017
Calling your cell arrays AA, AA1, AA2 is not a particularly good idea. These are completely meaningless names that just obfuscate the purpose of the code and makes it hard to debug.
Anyway. It's not clear what you mean by delete AA1{x}{x}. Do you want to change AA1{x} into a 1x35 cell array, or you want the content of AA1{x}{x} to be an empty matrix?
Either way,
AA1 = AA; %please use better names
for diagidx = 1:numel(AA) %don't hardcode sizes
AA1{diagidx}(diagidx) = []; %to get 1x35 cell arrays
%or
%AA1{diagidx}{diagidx} = []; %to get 1x36 cell array with column x an empty matrix
end
As per Stephen's comment, your data structure is making it harder to manipulate. I would recommend you use a 2D cell array:
AA = vertcat(AA{:});
  1 Comment
neamah al-naffakh
neamah al-naffakh on 14 Jan 2017
Dear Guillaume, you are really so kind. many thanks for both of you .
please if i want to use
AA = vertcat(AA{:});
how the code look like ? because i tried your code, it doesnt work when i add this command first?
AA = vertcat(AA{:});
but when i remove it, it works without problem?
could you please help me with that?
AA = vertcat(AA{:});
AA1 = AA; %please use better names
for diagidx = 1:numel(AA) %don't hardcode sizes
AA1{diagidx}(diagidx) = []; %to get 1x35 cell arrays
%or
%AA1{diagidx}{diagidx} = []; %to get 1x36 cell array with column x an empty matrix
end

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!