I want to change the name of elements in a variable

5 visualizzazioni (ultimi 30 giorni)
I have a variable name countries, and there are few countries in there; UK, Canada, France, Italy, Japan and United States. How do I change the name 'United States' to 'US' in script?
  6 Commenti
Kevin Holly
Kevin Holly il 10 Ott 2021
Was there a user interface when you imported the data? If so, there was an option on how to import it. I believe the default is a table. Can you look in the workspace window and tell me what variables you see. It should state the type of variable as well.
Kevin Holly
Kevin Holly il 10 Ott 2021
If the country names repeat in an array and you wanted to replace all of the "United States" with "US", you can use strrep .
strrep(Countries,"United States","US")

Accedi per commentare.

Risposta accettata

Kevin Holly
Kevin Holly il 10 Ott 2021
Modificato: Kevin Holly il 10 Ott 2021
You can save a string array with those names as such:
Countries = ["UK";"Canada"; "France";"Italy";"Japan";"United States"];
You can change the 6th element in the array as such:
Countries(6) = "US"

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by