Effacer les filtres
Effacer les filtres

How do I query 200 cells containing datasets of unequal lengths using one data having complete data?

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Jan
Jan le 10 Nov 2022
Modifié(e) : Jan le 11 Nov 2022
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 commentaire
Stephen Tete
Stephen Tete le 10 Nov 2022
Modifié(e) : Stephen Tete le 10 Nov 2022
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by