Assign Character based on condition
Ältere Kommentare anzeigen
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);
Akzeptierte Antwort
Weitere Antworten (1)
Turbulence Analysis
am 18 Feb. 2022
0 Stimmen
1 Kommentar
Voss
am 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!
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!