How do I enter same string input in a vector?

8 ビュー (過去 30 日間)
Charlotte Wargniez
Charlotte Wargniez 2022 年 7 月 26 日
コメント済み: Walter Roberson 2022 年 7 月 28 日
I am trying to create a vector (not a string array) with repeated string entries such as "30 T" for a specific length.
for i = 1:879
S = Contour1(i);
Sy = S.Lon
Sx = S.Lat
UTMZ = zeros(length(Sy),1);
UTMZ(:)= ['30 T'];
GeoDeg = utm2deg(Sx',Sy',UTMZ)
plot(Sx,Sy)
i;
end
After creating a vector, I can't seem to have the entry repeat itself. I can't also manually entre the values in each vector because the length of the vector varies for each loop.
Any sugestions on how to entre a repeating string within a vector?

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 7 月 26 日
UTMZ = repmat('30 T', 1, length(Sy)).';
  4 件のコメント
Charlotte Wargniez
Charlotte Wargniez 2022 年 7 月 27 日
編集済み: Charlotte Wargniez 2022 年 7 月 27 日
i see. Thanks.
I was able to run the code if i created a cell array and then characterized each entry:
for i = 1:879
S = Contour1(i);
Sy = S.Lon;
Sx = S.Lat;
UTM = repmat({'17 T'}, length(Sy), 1);
UTMZ = char(UTM);
[SmokeLat, SmokeLon] = utm2deg(Sx',Sy',UTMZ);
plot(SmokeLat,SmokeLon)
i;
end
Thanks again!
Walter Roberson
Walter Roberson 2022 年 7 月 28 日
I found that function in the File Exchange. It is an odd function -- it requires that the third parameter be a 2d array of character with four columns and the letter codes have to be in the 4th column.
The particular case of a 2D array of char is the one I referred to in the line about a Battleships map. The technique you used with repmat of a cell array and char() that, is fine, but you could also be more efficient as
UTMZ = repmat('17 T', length(Sy), 1);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by