mzaya
mzaya

Reputation: 15

Replace values in one column in multiple cells in array

I'm trying to replace the 5th column in each cell in a cell array with the 5th column of each cell from another cell array. I made the following function, which does this but also replaces the values in all other columns with 0. How do I do this without deleting all other values from the other columns. The function is:

function [X]=replace_cells(cell) 
X={};
for i=1:length(cell)
   X{i}(:,[5])=cell{i}(:,[5]);
end

end

Upvotes: 1

Views: 133

Answers (1)

Rash
Rash

Reputation: 4336

Your function doesn't replace the columns because the function creates X while it should be an input, try this function,

function X = replace_cells(c,X) 
for i = 1 : length(c)
   X{i}(:,5)=c{i}(:,5);
end

cell is a Matlab function don't use it as name for variables.

Upvotes: 1

Related Questions