How do I query 200 cells containing datasets of unequal lengths using one data having complete data?
1 次查看(过去 30 天)
显示 更早的评论
I have this code that overwrites nan values (stored in refom) with data from different cells (A). A has 200 cells each containing datasets
The problem is when I use this for loop below to loop through the data in the cells it does overwrite the nan values as I expect
Nevertheless, in rows where there is no data I expect it to leave the NANs but what happens is that it rather put some random
values in positions where there is no data.
On the other hand when I try to do it out of the for loop using just two datasets it works.
What is missing please?
rf = {};
refom = nan(size(A{1})); %A{1} has full dataset hence using its size to create NANs
for i = 1:length(A)
r_new = A{i}(:,:);
[~,rows] = ismember(r_new(:,3),A{1}(:,3)); %compare col 3 of the two data
refom(rows,:) = r_new; % overwrite NaNs and keep NANs for rows without data
rf = [rf; refom]; %append to cell dustbin rf
end
0 个评论
采纳的回答
Jan
2022-11-10
编辑:Jan
2022-11-11
The data are not random, but the values of the former iterations. You do not reset the contents of refom to NaN in each iteration.
refom = nan(size(A{1}));
match = A{1}(:, 3); % [EDITED] 3 column only
for i = 1:numel(A)
r_new = A{i};
[~,rows] = ismember(r_new(:,3), match);
refom(rows, :) = r_new;
rf = [rf; refom];
refom(:) = NaN;
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!