我有3個字符串類似如下:訪問字符串元素在MATLAB
world=["America", "Europe"]; % Parent String
America=["USA", "Brazil", "Argentina"]; % Child1 String
Europe=["France", "Germany", "England"]; % Child2 String
我要訪問的子字符串從父字符串中的元素(國名)(世界)和在for循環中使用它以便進一步操作。我正在嘗試以下方式:
for i=1:2
d=world(i); % Temporary variable to store the continent name
for j=1:3
disp(d(j)); % Throws an Error: "Index exceeds Matrix dimensions
end
end
我在做什麼錯?任何幫助將不勝感激。
感謝您的及時回覆。 我的預期輸出是直接顯示來自父字符串的國家名稱(不使用大陸字符串) –
'd'可以是美國或歐洲字符串;不作爲變量,因此不能像變量一樣索引 –
d = America(當i = 1時,在第一次迭代中) –