I want to change the name of elements in a variable
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Krutik Gamit
il 10 Ott 2021
Commentato: Kevin Holly
il 10 Ott 2021
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
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
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")
Risposta accettata
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"
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Characters and Strings 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!