how to make an identifer for string variables

1 回表示 (過去 30 日間)
Linden
Linden 2014 年 4 月 30 日
コメント済み: Stephen23 2024 年 8 月 22 日
Hi I have a list of string variables, which all ends with "_STI". How can I group them together so that I can perform the same operations to them. For example, I want to assign a number to all the variables ends with "_STI". Thanks very much

回答 (1 件)

Prateekshya
Prateekshya 2024 年 8 月 22 日
Hello Linden,
Assuming that the variables are doubles, here is a small example to achieve value assignment by grouping the variables together:
% Step 1: Get a list of all variables in the workspace
vars = who;
% Step 2: Initialize a number to assign
assign_value = 42; % Replace with the number you want to assign
% Step 3: Loop through the variables and perform operations
for i = 1:length(vars)
var_name = vars{i};
if endsWith(var_name, '_STI')
% Use dynamic field names to assign a value
assignin('base', var_name, assign_value);
end
end
You can modify the code according to your data type requirement.
I hope this helps!

カテゴリ

Help Center および File ExchangeLinear Model Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by