how can i save the results of multiple executions?
조회 수: 3 (최근 30일)
이전 댓글 표시
hello
if i have the fallowing situation
t=0.1:1:10
for t-ang=t*pi/18
function that depend on t-ang
then i plot the result of this function with the t-ang
end
so the function execuited periodically for each value of t and plot each case.
but it only give me the last value of the fuction by overwriting previous results how can i save the results of each value
댓글 수: 1
Walter Roberson
2023년 2월 7일
for t-ang=t*pi/18
... does that mean you are calculating
syms t ang
ANG = simplify(solve(t-ang == t * sym(pi) / 18, ang))
답변 (1개)
Walter Roberson
2023년 2월 7일
You should learn this pattern:
tvals = 0.1:1:10;
num_t = numel(tvals);
results = zeros(num_t,1);
for t_idx = 1 : num_t
t = tvals(t_idx);
value = some calculation in t;
results(t_idx) = value;
end
plot(tvals, results)
When you use this pattern, the entries in tvals do not need to be sorted or equally spaced or unique. In some cases where those do happen to be the case, you can abbreviate the code. For example,
results = zeros(10,1);
for K = 1 : 10
value = some calculation in (K-0.9);
results(K) = value;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!