필터 지우기
필터 지우기

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