Error too many input arguments using equals equals
2 次查看(过去 30 天)
显示 更早的评论
Each row of the table want contains information about a specific person. Each row of the cell array (I tried having it be a table and got different errors) roster has information about a specific person and their subject ID. I want to get the subject ID of every person in the table want. To do this, I am saying (I think I'm saying) for every row in want to find the row in roster that has the same value in column 3 as want's column 3 and the same value in roster's column 2 as want's column 2. Then the array PTID will print all of the subject IDs that I want.
Errors:
-line 5: too many input arguments for == (it does this with and without the and)
-line 5: I think the {:,3} and {:,2} might not necissarily mean the same row in both cases
-line 1 & 2 (currently not an error, but might cause other errors): having want be a table and roster be a cell doesn't allow it to do the same things as matrices does, but I am unable to turn them into matrices.
-previously I had the error == was an undefined operator for cell type, but fixed it by using curly brackets
1 want=readtable('miniStable_MCI.csv');%the file to copy into matrix
2 roster = table2cell(readtable('miniROSTER.csv'));
3 PTID=zeros(4439);
4 for j = 1:4439
5 rosterrow=find((roster{:,3}==want{j,3})&(roster{:,2}==want{j,2}));%row 3
6 ...has RID, row 2 has site ID, and both values must be the same as the
7 ...2 values in the other matrix
8 PTID(j)=roster(rosterrow,5);%roster has subject ID in column 5
9 end
sprintf(PTID)
example rows of want:
[ADNI1 39 267 2035; ADNI1 5 267 50; ADNI2 39 19 50]
example row of roster:
[ADNI1 39 82 50 149_S_0082; ADNI1 14 19 002_S_0019; ADNI1 5 267 50 014_S_0267]
So row 2 of want would correlate with row 3 of roster and output subject ID 014_S_0267]
Thank you so much!!
0 个评论
回答(1 个)
Voss
2024-2-13
"I tried having it be a table and got different errors"
Let me keep both want and roster as tables.
want = table({'ADNI1';'ADNI1';'ADNI3'},[39; 5; 39],[267; 267; 19],[2035; 50; 50])
roster = table({'ADNI1';'ADNI1';'ADNI1'},[39;14;5],[82;NaN;267],[50;19;50],{'149_S_0082';'002_S_0019';'014_S_0267'})
for-loop solution:
N = size(want,1);
PTID = cell(N,1);
PTID(:) = {'<NO MATCH>'};
for jj = 1:N
rosterrow = find((roster{:,3}==want{jj,3})&(roster{:,2}==want{jj,2}), 1);
if ~isempty(rosterrow)
PTID(jj) = roster{rosterrow,5};
end
end
disp(PTID)
vectorized solution:
N = size(want,1);
PTID = cell(N,1);
PTID(:) = {'<NO MATCH>'};
[ism,idx] = ismember(want{:,[2 3]},roster{:,[2 3]},'rows');
PTID(ism) = roster{idx(ism),5};
disp(PTID)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!