Azzera filtri
Azzera filtri

Converting String to Character,

74 visualizzazioni (ultimi 30 giorni)
Sean St Cyr
Sean St Cyr il 7 Lug 2020
Risposto: Saurabh il 29 Mag 2023
Hi, I got an error saying that my code below for the Hit, Miss, Total Miss, and Bullseye is currently a string and needs to be "of data type char" and I was wondering if someone could help
function[zone,Points]=RQ18_18(X,Y)
distance=sqrt(X^2 + Y^2);
Bluedistance=3;
Greendistance=2;
Reddistance=1;
if( distance<=Reddistance)
Points=4;
zone="Bullseye";
elseif(distance>Reddistance && distance<=Greendistance)
Points=2;
zone="Close";
elseif(distance>Greendistance &&distance<=Bluedistance)
Points=1;
zone="Hit";
elseif((X>=4 && X<=-4) && (Y>=-4 && Y<=-4))
Points=0;
zone="Miss";
else
Points=-1;
zone="Total Miss";
end
end
  3 Commenti
Sean St Cyr
Sean St Cyr il 7 Lug 2020
Thank you, I got it fixed
dpb
dpb il 7 Lug 2020
Just a stylistic comment -- it helps ALOT to indent code constructs in being able to read and debug code...sure, the machine doesn't care, but it doesn't do the hard work of writing the code.

Accedi per commentare.

Risposte (1)

Saurabh
Saurabh il 29 Mag 2023
What you can do is to convert the string to char using char() function.
for example:
Bullseye = char(Bullseye );
let me know if this works or not.

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by