How to apply a function to an specific column of all variables?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Larissa Perez
am 17 Nov. 2016
Kommentiert: Larissa Perez
am 18 Nov. 2016
Hi everyone! I'm new to Matlab, so I'm sure this is a silly question.
I have about 20 variables, all same size matrix. I would like to turn all the values above 50 or below -50 in the first column into NaN, for all the variables. Can someone help me with that? This is what I have been trying to do:
myvars = who;
for i = 1:length(myvars)
data = eval(myvars{i});
shear = data(:,1);
shear(shear>50)=NaN;
shear(shear<-50)=NaN;
data(:,1) = shear;
eval(myvars{1}) = data;
end
1 Kommentar
KSSV
am 17 Nov. 2016
You have variables saved in workspace which are matrices and in there in first column you want nan? What problem you are facing now with the above code?
Akzeptierte Antwort
James Tursa
am 17 Nov. 2016
Bearbeitet: James Tursa
am 17 Nov. 2016
Try this:
eval([myvars{i} ' = data']);
0 Kommentare
Weitere Antworten (1)
Jan
am 17 Nov. 2016
Don't do this. It is a bad programming style, because it impedes the debugging and performance. You find many discussions in this forum concerning eval, e.g. http://www.mathworks.com/matlabcentral/answers/194902-how-can-use-a-for-loop-to-name-a-matrix#answer_172980.
2 Kommentare
Siehe auch
Kategorien
Mehr zu Variables 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!