Error with undefined operators
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi guys,
I currently have this code to generate a spaghetti plot that shows the difference between two patient groups, where APPRDX_enrol = 1, and APPRDX_enrol = 2:
%t = readtable('PPMIMERGE_selectedcolumns2.csv'); Interestingly, if I uncomment this line, and comment the line below, it works fine
t = readtable('datasetfilteredVLTANIM.csv');
figure(1);
%Parkinson's
SPAGLAB(t(t.APPRDX_enrol==1, :), 'Years_bl', 'VLTANIM', 'PATNO', '-r.');
%Controls
SPAGLAB(t(t.APPRDX_enrol==2, :), 'Years_bl', 'VLTANIM', 'PATNO', '-g.');
function h = SPAGLAB(t, Years_bl, VLTANIM, PATNO, plot_format)
if nargin < 5
plot_format = '-b.';
end
subj_ids = t.PATNO;
uIds = unique(subj_ids);
n = length(uIds);
hold on;
for i = 1:n
if isnumeric(subj_ids)
index_i = find(t.(PATNO) == uIds(i));
else
index_i = find(strcmp(t.(PATNO),uIds{i}));
end
x_i = t.(Years_bl)(index_i);
y_i = t.(VLTANIM)(index_i);
h = plot(x_i, y_i, plot_format);
title('Graph displaying VLTANIM scores for PD vs Control');
xlabel('Years Since Baseline');
ylabel('VLTANIM Score');
end
hold off;
end
I get this error:
Undefined operator '==' for input arguments of type 'cell'.
Any ideas?
댓글 수: 3
Ioannis Andreou
2020년 2월 2일
It might be, that
t.APPRDX_enrol = {1}
instead of
t.APPRDX_enrol = 1
. The error then appears because cells can not be compared with ==
답변 (1개)
Guillaume
2020년 2월 2일
The cause for the error is simple. In the file that doesn't work, at least one row of the APPRDX_enrol column contains non-numeric data. As a result, you end up with a cell array (probably of char vectors) instead of a column vector.
So, you either need to modify your code so it can cope with non-numeric data, but it's unclear what should be done in this case, or fix your import, it's hard to tell you what to do without an example file, or fix the file so the column only contains numeric data.
If the data in the files is confidential, it could be replaced by dummy data, as long as the format and numeric vs non-numeric is preserved.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!