Assign Character based on condition
古いコメントを表示
Hi,
In the below script, if ii = 3, I would like to define X_5 (:,1) = X_5 (:,1)*(2); and for ii =2 it should be Y i.e.
Y_5 (:,1) = Y_5 (:,1)*(2),
may I know how to define this ??
ii = 3;
X_5 (:,1) = X_5 (:,1)*(2);
X_10 (:,1) = X_10 (:,1)*(2);
X_15 (:,1) = X_15 (:,1)*(2);
X_20 (:,1) = X_20 (:,1)*(2);
X_25 (:,1) = X_25 (:,1)*(2);
X_30 (:,1) = X_30 (:,1)*(2);
採用された回答
その他の回答 (1 件)
Turbulence Analysis
2022 年 2 月 18 日
0 投票
1 件のコメント
Voss
2022 年 2 月 18 日
If all the X_5, X_10, etc. are the same size, and the Y_'s are a different size (but all Y_'s are the same amongst themselves), then you can combine all the X_'s into one, and all the Y_'s into one, etc., and have three variables - one for X, one for Y, one for Z.
Or you can put whatever is the same size together in matrices and put different size matrices into a cell array and do operations on each cell of the cell array using cellfun().
The point is, there are always better options than having to write and maintain highly redundant code, but whatever works for you is what works since you're the one dealing with it!
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!