フィルターのクリア

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 Center および File ExchangeCreating 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