Add '_max' to odd variable names and '_min' to even ones.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Usune Elizondo
am 22 Sep. 2021
Kommentiert: Usune Elizondo
am 22 Sep. 2021
I have a table where just even variables have a name, the rest (odd) have automatic name set by Matlab.
Something like this:
I want to have Var1 = t_max and t = t_min, then Var3 = ang_azi_max and ang_azi = ang_azi_min.
Hope someone can help ;)
0 Kommentare
Akzeptierte Antwort
Stephen23
am 22 Sep. 2021
T = array2table(rand(5,8),'VariableNames',{'Var1','t','Var3','ang_azi','Var5','vel_azi','Var7','acc_azi'})
T.Properties.VariableNames(1:2:end) = strcat(T.Properties.VariableNames(2:2:end),'_max');
T.Properties.VariableNames(2:2:end) = strcat(T.Properties.VariableNames(2:2:end),'_min')
Weitere Antworten (1)
Simon Chan
am 22 Sep. 2021
Suppose the table is called T, then try the following:
T.Properties.VariableNames(1:4) = {'t_max','t_min','ang_azi_max','ang_azi_min'}
3 Kommentare
Simon Chan
am 22 Sep. 2021
Try this:
temp = T.Properties.VariableNames(2:2:end);
temp_min = cellfun(@(x) strcat(x,'_min'),temp,'UniformOutput',false);
temp_max = cellfun(@(x) strcat(x,'_max'),temp,'UniformOutput',false);
temp_combine = vertcat(temp_max, temp_min);
T.Properties.VariableNames = temp_combine(:);
Stephen23
am 22 Sep. 2021
@Simon Chan: STRCAT also operates on cell arrays of char vectors, so CELLFUN is entirely superfluous.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!