eval function in for-loop and change of numbers bigger through NaN
이전 댓글 표시
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
"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
2024년 6월 10일
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
2024년 6월 10일
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
