Error with undefined operators

1 次查看(过去 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 个评论
Barnaby Pickering
Hi Guillaume,
I'll add in the full error message:
Warning: Column headers from the file were modified to make them valid MATLAB identifiers
before creating variable names for the table. The original column headers are saved in the
VariableDescriptions property.
Set 'PreserveVariableNames' to true to use the original column headers as table variable
names.
Undefined operator '==' for input arguments of type 'cell'.
Error in SPAGHETTIPLOT (line 10)
SPAGLAB(t(t.APPRDX_enrol==1, :), 'Years_bl', 'VLTANIM', 'PATNO', '-r.');
Unfortunately, I cannot add the full files, as they are patient data.
Ioannis Andreou
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
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.

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by