Undefined unary operator '-' for input arguments of type 'string error
Show older comments
I am going to show x axis in scatter plot by text label like below with positive and negative signs however I get this error
"Undefined unary operator '-' for input arguments of type 'string' "
Can someone please assist in rectifying?
n= ["-240-260";"-220-240";"-200-220";"-180-200";"-160-180";"-140-160";"-120-140";"-100-120";"-80-100";"-60-80";"-40-60";"-20- 40";"0-20";"0+20";"+20+40";"+40+60";"+60+80";"+80+100";"+100+120";"+120+140";"+140+160";"+160+180";"+180+200";"+200+220";"+220+240"];
y1 = [0,0,0,0,0,0,0,0,0,0,0,0.04,0.32,0.56,0.08,0,0,0,0,0,0,0,0,0,0];
y2 = [0,0.05,0.05,0.05,0,0.1,0,0,0.2,0.3,0.1,0.1,0.05,0,0,0,0,0,0,0,0,0,0,0,0];
x=categorical(n);
plot(x,y1,'r--o', x,y2,'k--o');
5 Comments
Alan Stevens
on 7 Jul 2020
n= ["-240-260";-"220-240";"....
Look carefully at the second entry! I think you should have:
n= ["-240-260";"-220-240";"....
Rik
on 7 Jul 2020
@Alan, you should probably move that to the answer section.
Elnaz P
on 7 Jul 2020
Elnaz P
on 7 Jul 2020
Accepted Answer
More Answers (1)
Alan Stevens
on 7 Jul 2020
Why not just:
y1 = [0,0,0,0,0,0,0,0,0,0,0,0.04,0.32,0.56,0.08,0,0,0,0,0,0,0,0,0,0];
y2 = [0,0.05,0.05,0.05,0,0.1,0,0,0.2,0.3,0.1,0.1,0.05,0,0,0,0,0,0,0,0,0,0,0,0];
x=-250:20:230;
plot(x,y1,'r--o', x,y2,'k--o');
This plots the "y" points in the middle of your "x" bands.
2 Comments
Elnaz P
on 7 Jul 2020
Alan Stevens
on 7 Jul 2020
Edited: Alan Stevens
on 7 Jul 2020
Where does it differ?
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!