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

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

 채택된 답변

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개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

A
A
2012년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by