フィルターのクリア

Rename substring in table

2 ビュー (過去 30 日間)
Luca Re
Luca Re 2023 年 9 月 28 日
コメント済み: Luca Re 2023 年 9 月 30 日
this is a table with field "Name"
i want to search if name exit in table
example:
name=Preset1
name exist in table ? yes
Then i rename "Preset1" in Preset1_1;
If Preset1_1 exist in table i rename in Preset1_2 ...if exist i rename in Preset1_3..(I add a number following the "_")

採用された回答

Walter Roberson
Walter Roberson 2023 年 9 月 28 日
編集済み: Walter Roberson 2023 年 9 月 28 日
As a utility, see matlab.lang.makeUniqueStrings -- which already happens to append an underscore and a number. So if you were to make unique strings of name with respect to the existing entries in the Name field...
mask = YourTable.Name == string(name);
if any(mask)
newname = matlab.lang.makeUniqueStrings(name, YourTable.Name);
YourTable.Name(mask) = newname;
end
  16 件のコメント
Walter Roberson
Walter Roberson 2023 年 9 月 30 日
I am still stuck on the question of whether LoadPreset_Struct(pr) can return a struct that has a numeric value in the Name field ?
If so then
[~,Preset.Name,~]=fileparts(Preset.Name);
would fail with an error message. It would only succeed if the Name field was character vector or cell array of character vector or string array.
Luca Re
Luca Re 2023 年 9 月 30 日
Preset is a struct but Preset.Name is a string
whos Preset.Name
Preset =
struct with fields:
Name: "Preset3_1"
....

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by