Contains in cells extracted from a structure runs into char class problems
Hi everyone,
Gonna try to be brief. Basically I have a structure with a certain number of columns, and I need to know if a certain element already exists in the column, as to retrieve its index and then check other columns on the same row.
So if indications is the struct, and curr_ID is what I am trying to look for I coded something like this:
if secondPass && contains({indications.Patient_ID}, curr_ID)
idx = find(contains({indications.Patient_ID}, curr_ID),1, ‘first’);
end
(…)
Now the problem is that contains is outputing and error saying that "First argument must be text". Has anybody encountered this?
To be clear, contains works with cells, and if you do A = {indications.Patient_ID} you will see that A is a cell populated with the text from all the columns of Patient_ID. I also use contains with a different cell (ZZ for example) that originates from a function and there it works fine. I don’t know if anybody has noticed but when using A={struct.field} what I actually get when looking using the variable viewer is a something that looks like this:
‘ID111’
‘ID112’
‘ID113’
…
However, for my other cells of chars when looking using the varaible viewer I do not see the ‘ around the words. I wonder if this is a problem even though both class(A{1,1}) and class(ZZ{1,1}) both come out as char.
Thanks in advance for the help!Hi everyone,
Gonna try to be brief. Basically I have a structure with a certain number of columns, and I need to know if a certain element already exists in the column, as to retrieve its index and then check other columns on the same row.
So if indications is the struct, and curr_ID is what I am trying to look for I coded something like this:
if secondPass && contains({indications.Patient_ID}, curr_ID)
idx = find(contains({indications.Patient_ID}, curr_ID),1, ‘first’);
end
(…)
Now the problem is that contains is outputing and error saying that "First argument must be text". Has anybody encountered this?
To be clear, contains works with cells, and if you do A = {indications.Patient_ID} you will see that A is a cell populated with the text from all the columns of Patient_ID. I also use contains with a different cell (ZZ for example) that originates from a function and there it works fine. I don’t know if anybody has noticed but when using A={struct.field} what I actually get when looking using the variable viewer is a something that looks like this:
‘ID111’
‘ID112’
‘ID113’
…
However, for my other cells of chars when looking using the varaible viewer I do not see the ‘ around the words. I wonder if this is a problem even though both class(A{1,1}) and class(ZZ{1,1}) both come out as char.
Thanks in advance for the help! Hi everyone,
Gonna try to be brief. Basically I have a structure with a certain number of columns, and I need to know if a certain element already exists in the column, as to retrieve its index and then check other columns on the same row.
So if indications is the struct, and curr_ID is what I am trying to look for I coded something like this:
if secondPass && contains({indications.Patient_ID}, curr_ID)
idx = find(contains({indications.Patient_ID}, curr_ID),1, ‘first’);
end
(…)
Now the problem is that contains is outputing and error saying that "First argument must be text". Has anybody encountered this?
To be clear, contains works with cells, and if you do A = {indications.Patient_ID} you will see that A is a cell populated with the text from all the columns of Patient_ID. I also use contains with a different cell (ZZ for example) that originates from a function and there it works fine. I don’t know if anybody has noticed but when using A={struct.field} what I actually get when looking using the variable viewer is a something that looks like this:
‘ID111’
‘ID112’
‘ID113’
…
However, for my other cells of chars when looking using the varaible viewer I do not see the ‘ around the words. I wonder if this is a problem even though both class(A{1,1}) and class(ZZ{1,1}) both come out as char.
Thanks in advance for the help! programming MATLAB Answers — New Questions