I have a string array called 'Countries' which contains [120x1]. The variable contents Canda, France, Italy, Japan, United KIngdom, and United States. (So around 15 Canda, 20 France..and so on) What I want to do is write a loop that looks into the variable 'Countries' and checks each element and replaced 'United States' with 'US'. I am new to the 'for' command, so I am not sure how to write my code. Any help would be much appreciated.

 採用された回答

Rik
Rik 2021 年 10 月 15 日

0 投票

Why didn't you mention this is homework? (I have seen this exact situation from another user this week, so barring evidence to the contrary I will treat this as homework)
You don't need a loop. If no other entry contains this text you can use strrep (so watch out for "Mexican United States"), otherwise you'll need ismember.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

タグ

質問済み:

2021 年 10 月 15 日

回答済み:

Rik
2021 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by