sharing values of elements in a matrix
2 次查看(过去 30 天)
显示 更早的评论
Hi All, I've attached my questions for your reference - It was hard to paste here.
5 个评论
Stephen23
2019-8-9
编辑:Stephen23
2019-8-9
JL's incorrectly posted "Answer" moved here and formatted correctly:
Hi Darova, what I did was first multiplied W.*Z to get X0
Then I used this code from star strider
for k = 1:size(Y,1)
[~,Zc] = find(Y(k,:) ~= 0, 1, 'last'); % Last Non-Zero Column
Z2(k,:) = Y(k,Zc); % Element Of Last Non-Zero Column
end
Z = accumarray([Z2 Y(:,1)], X0)
Z1 = [Z, zeros(size(Z,1),1 )];
Z2 = [Z.'; zeros(1,size(Z,1 ))];
Znew = Z1 + Z2
With this code, I get
X =
[ 0 0 12.09 11.74;
0 0 11.74 11.74;
12.09 11.74 0 11.74;
11.74 11.74 11.74 0;]
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!