필터 지우기
필터 지우기

if the cell duplicated put last column in the previous row

조회 수: 1 (최근 30일)
Amr Hashem
Amr Hashem 2015년 5월 12일
댓글: Walter Roberson 2015년 5월 14일
i run this code but it gives an error:
j=1;
rowsize=length(defs);
data1=cell([rowsize,C2]); % create array with size [R,C]
for j=1:length(defs) % loop over Mdr of defib
querymdr=data2{j,1}; % save MDR numbers
y=alldata{:,1};
idx= find(y==querymdr); % find in alldata MDR equals def
record=[alldata{idx(1),:}]; % copy the 1st search result
for k=2:length(idx)% over all MDR number of text
record = [record,(alldata(idx(k),6))];
end
data1(j,:)=record; % put combined record into result table
end
what is the wrong thing ?
  댓글 수: 5
Walter Roberson
Walter Roberson 2015년 5월 14일
What is class(y) and size(y) when the problem occurs?
Also your code does not account for the possibility of there being no match.
Amr Hashem
Amr Hashem 2015년 5월 14일
i adjust the code to be :
for j=1:length(defs)
querymdr=data2(:,1);
y=alldata(:,1);
idx= find(y==querymdr); % find matched cells
record= alldata(idx,:);
it gives me an error in idx= find(y==querymdr); % y has 37*1 cell and querymdr has 5*1 cell
they are matched columns, but y has 37 cell and querymdr has 5 only. i want to find the matched cells.
what is wrong?

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2015년 5월 14일
Maybe idx is empty (i.e., the find didn't result in a match). Do this to verify:
dbstop if error
Then run your code. When the error occurs, the execution will pause and you can examine variable sizes to confirm the problem and why it occurred.
  댓글 수: 2
Amr Hashem
Amr Hashem 2015년 5월 14일
i adjust the code to be :
for j=1:length(defs)
querymdr=data2(:,1);
y=alldata(:,1);
idx= find(y==querymdr); % find matched cells
record= alldata(idx,:);
it gives me an error in idx= find(y==querymdr); % y has 37*1 cell and querymdr has 5*1 cell
what is wrong?
Walter Roberson
Walter Roberson 2015년 5월 14일
You created a new Question for this, so no point answering here.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by