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

Guillaume
Guillaume 2020년 2월 2일
Please give us the full text of the error message, everything in red, particulalry the bit that shows the line responsible for the error, so we don't have to guess.
Interestingly, if I uncomment this line, and comment the line below, it works fine
It's not particulalry surprising, you're importing two different files, there's no guarantee that they'll import the same way. Attaching an example of the two files would help.
Barnaby Pickering
Barnaby Pickering 2020년 2월 2일
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일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 2월 2일

답변:

2020년 2월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by