error-CAT arguments dimensions are not consistent.

조회 수: 8 (최근 30일)
kash
kash 2012년 1월 29일
i have a code
out = [d1, d(ismember(d(:,1),d1(:,1),'rows'),1:end)]
my values are
d=[1 2 3 ;5 6 8 ]
d1=[1 ;1]
i need the answer as
1 1 2 3
1 1 2 3
please help
  댓글 수: 1
kash
kash 2012년 1월 29일
i get error wen my code is
out = [d1, d(ismember(d(:,1),d1(:,1),'rows'),1:end)]
error is
CAT arguments dimensions are not consistent
please help

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

답변 (1개)

Walter Roberson
Walter Roberson 2012년 1월 29일
d(:,1) is [1;5] . d1(:,1) is [1;1] . You ask ismember() for matching rows. The row [1] of d(:,1) matches the row [1] of d1(:,1) so the first value returned by ismember() is true. The row [5] of d(:,1) does not match any rows of dl(:,1) so the second value returned by ismember is false. The ismember result is thus [true;false] . You use that [true;false] as the first index of d, and you select all columns of d through the second index, so the result is going to be to select just the first row, d(:,1) which is [1 2 3]. You try to combine that single row via horzcat, with the multiple rows of d1, so you get an error.
The above is why you get an error. In order for us to show you how to get the output you want, you will need to explain the rules you want.
I note that if you were to use
[tf, ua, ub] = ismember(d1(:,1), d(:,1), 'rows'); %d1 and d change places
out = [d1(tf), d(ub,:)];
then that would happen to give the output you say you need. This is probably just a coincidence, however.
  댓글 수: 7
kash
kash 2012년 1월 29일
Thanks walter,
in other code
ind=nchoosek(1:100,2);
data12=[1:100]
FC1=data12(ind)
my FC1 has 2 column of 4900 rows,but i need 2 columns and 50 rows,by seleccting some values ,please help
for example selecting 2 values from each 100 ,(wen selecting column values must not change)
Walter Roberson
Walter Roberson 2012년 1월 29일
You have an existing Question for that, http://www.mathworks.com/matlabcentral/answers/27353-selecting-top-values . It can be discussed there.

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

카테고리

Help CenterFile Exchange에서 Fluid Dynamics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by