# How to read a character from a script and extract the number in the same line.

1 view (last 30 days)
Han on 8 Apr 2022
Commented: Han on 28 Apr 2022
[ Figure 1 ]
[ Figure 2 ]
Hello.
In cell d of Figure 1, I created a script as shown in Figure 2 to output the number corresponding to the same row as 'Failed' among the characters in the first column.
However, on line 3 of the script, an error occurred stating that the expression on the left of = is not valid.
I don't understand why it's not valid, so I'm asking.
thank you.

Walter Roberson on 8 Apr 2022
Edited: Walter Roberson on 8 Apr 2022
In MATLAB statements, there are four ways that = can be used:
• there can be a simple or indexed variable or list of simple or indexed variables in [], then a single = and then a function call or expression whose output is to be assigned to what occurs on the left
• There can be a statement that starts with for and then an un-indexed variable, and then a single = and then an expression; this creates a for loop
• Inside a () parameter list for a function call, there can be a simple unindexed variable name, then a single = and then a value; this is the same as using a name/value pair A=B being the same as "A", B
• You can have a pair of equal signs together, == to express a necessary logical relation
Your code uses a single = in the context of an if . That is not an assignment statement, not a for loop, and there is an indexed expression to the left of the = so this cannot be a shortcut for a name/value pair.
You should have used == to express the logical relation for the test.
However... you have the further problem that == is not defined between cell array elements. You can fix this in any of the following ways:
• if isequal(d(i,j), {'Failed'})
• if string(d(i,j)) == "Failed" %notice the double quotes
• if strcmp(d{i,j}, 'Failed')
• if d{i,j} == "Failed" %notice the double quotes
Han on 28 Apr 2022
Thank you!