eval function in for-loop and change of numbers bigger through NaN
Show older comments
I have 108 variables with same name but with consecutive numbering. Each of this variables I want to check if there is a value bigger 1000. When yes, then it will be exchanged through NaN.
I try to solve with eval and for-loop, but it doesn't work.
I know the function which changes a value bigger 1000 through NaN.
Function: Temperatur_1(Temperatur_1>1000)=NaN;
Dynamics variabels are: Temperatur_1, Temperatur_2, etc.
eval-function: eval(strcat('Temperatur_',num2str(e)))
for i=1:108
tbd
end
What is the function for checking each variable for > 1000 and saving it in the same variable?
Thank you in advance for your support and solution.
5 Comments
"I have 108 variables with same name but with consecutive numbering."
Why?
Why is the data designed in such a way so that processing it will be slow, complex, and inefficient?
"Thank you in advance for your support and solution."
Use arrays. Using arrays is what makes processing data easy. Using arrays is how MATLAB works.
So far you did not tell us the most important information: how did you get all of those variables into the workspace?
FD
on 10 Jun 2024
But I need the single arrays for plotting.
Instead of creating a large number of individual variables, why not simply index into that matrix? This avoids creating a large number of variables in your workspace, which IMO makes it much more difficult to locate the information you're interested in.
A = magic(5)
plot(A(:, 4), 'o-') % Plot the 4th column; no need to create a variable A4
FD
on 10 Jun 2024
A = magic(6)
[minValue, minLocation] = min(A, [], 1)
In column 4, based on the fourth elements of minValue and minLocation the minimum value of A is 12 and that occurs in row 5.
No need to create A1, A2, A3, A4, A5, and/or A6.
for n = 1:width(A)
fprintf("In column %d of A, the minimum value is %d" + ...
" and this occurs at (%d, %d).\n", n, minValue(n), minLocation(n), n)
end
Accepted Answer
More Answers (0)
Categories
Find more on Variables 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!