Assign Character based on condition
Show older comments
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);
Accepted Answer
More Answers (1)
Turbulence Analysis
on 18 Feb 2022
0 votes
1 Comment
Voss
on 18 Feb 2022
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!
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!