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 件のコメント
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!