Error using plot Invalid first data argument.
2 views (last 30 days)
Show older comments
When I try to run this code it gives me:"Error using plot
Invalid first data argument."
TCI=20;
q=52300;
cp=4182;
m=0:0.01:20;
TCO=q/cp*m+TCI
plot TCO
how to solve it?
0 Comments
Answers (1)
Walter Roberson
on 19 Jun 2021
MATLAB has a feature known as "command / function duality".
Any time you see a line of the form
WORD1 WORD2 .... WORDN
and there is no ( between WORD1 and the remainder of the expression, and WORD2 is not an assignment operator, then MATLAB understand that you are making a function call, and it converts the arguments into quoted strings.
Thus
plot TCO
is converted into the function call
plot('TCO')
and then you have the problem that 'TCO' is not a valid first argument for plot()
You see this kind of conversion a fair bit, but they tend to go unnoticed. For example,
hold on
is treated as a function call
hold('on')
There is no special processing to recognize hold specifically as a command; hold is not one of the special keywords known to MATLAB such as break or case : MATLAB just has a rule that says "no ( between what looks like a function name and what might be an argument? Convert the words into quoted strings and call the function with those!"
Anyhow, you want
plot(TCO)
but now you know more about why it happened.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!