Replace the first value in each cell of a cell array with the value from another cell array

1 次查看(过去 30 天)
I have a cell array containing the eigenvalues of a set of matrices. I have removed the first value from each of the cells in this array, and placed them in a matrix. These values are then manipulated via a set of thresholds based on a watermark image. I have then reconverted matrix of values to a cell array. I would now like to place the values from these new cells into the corresponding first location of the cells in the old array. Any idea's on how to do this?
ction Code follows: (The last line there is the trouble)
function D = fun(D,W)
Q = 5;
[i,j] = size(D)
F = cellfun(@(c) c(1), D); % grab the first value from each cell
disp(F); % Debug check
for a = 1:i % Process the values
for b = 1:j
Z = mod(F(a,b),Q);
if W(a,b) == 0
if Z<(3*Q)/4;
F(a,b) = F(a,b)+Q/4-Z;
else
F(a,b) = F(a,b)+5*Q/4-Z;
end
else
if Z<Q/4;
F(a,b) = F(a,b)-Q/4+Z;
else
F(a,b) = F(a,b)+3*Q/4-Z;
end
end
end
end
disp(F); % Debug check
F = num2cell(F); % Make the new cell array
disp(F); % Debug Check
D{1,1} = cellfun(@(F) F{1,1}, F); % No clue what to do here

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-4-18
Dnew = arrayfun(@(x,y)reshape([y,x{:}(2:end)],size(x{:})),D,F,'un',0)
OR
Dnew = arrayfun(@(x)reshape([F(x),D{x}(2:end)],size(D{x})),reshape(1:numel(F),size(F)),'un',0)

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by