필터 지우기
필터 지우기

How can I create a for cycle replacing text in a string array?

조회 수: 1 (최근 30일)
Barbab
Barbab 2018년 12월 4일
편집: Barbab 2018년 12월 4일
Hi there,
here's my problem, i have a vector such as:
vector1=["Home1" "Home2"]
a=5
for i=2:a
vector1(i+1)= %"Home&i+1" –> "Home3"
end
In short I want the cycle to change the string values in the vector.
Thank you in advance.

답변 (1개)

Akira Agata
Akira Agata 2018년 12월 4일
How about the following? In this case, vector(1,:) = ["Home1" "Home2"], ..., vector(5,:) = ["Home5" "Home6"].
vector0 = repelem("Home",5,2);
num = string([(1:5)',(2:6)']);
vector = join([vector0(:),num(:)],"");
vector = reshape(vector,size(vector0));

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by