Combine several matrix with NaNs
1 次查看(过去 30 天)
显示 更早的评论
I need to combine several matrixes of 500x500 elements that contains NaN. The matrixes must be combined in the way they keep their size but replace NaN by the elements of the other matrix.
I can easily do it for two matrixes: % Cx is a strucutre that I use to store these matrixes. Cx has several matrixes e.g Cx(1).Z Cx(2).Z ...
or=Cx(1).Z; %I want to add the elements to the first matrix (or)
nr=Cx(2).Z; % this is the second matrix
xn=isnan(or); %I select the NaN's
or(xn)=nr(xn); %I can get now combined elements between Cx(1).Z and Cx(2).Z, it works good until here
%I need to do the same now for all the other matrixes in my structure (Cx),so the combination will be cummulative, I mean use the resulting matrix from merging Cx(1).Z and Cx(2).Z to merge with Cx(3).Z, and then use this output to merge with Cx(4).Z .... and so on
I tough that a loop would be usefull
or=Cx(1).Z;
xn=isnan(or);
for i=1:numel(Cx)
nr=Cx(i).Z;
or(xn)=nr(xn);
end
but the output or is constantly overwrited and I can get a combination of the matrixes
any suggestion?
thanks in advance
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!