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

采纳的回答

Jan
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
  1 个评论
Stephen Tete
Stephen Tete 2022-11-10
编辑:Stephen Tete 2022-11-10
Im using column 3 to query the whole dataset please edit
[~,rows] = ismember(r_new(:,3), match(:,3));
The first one was very helpful, thank you alot

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by