필터 지우기
필터 지우기

Save all values of a calculation through a loop in a file

조회 수: 3 (최근 30일)
Joe
Joe 2023년 2월 22일
편집: Joe 2023년 3월 7일
V=[31:1:61];
angle=2;
for V=(31:1:61)
save myresults UVW0 -mat
end
Hello,
I need your help please!
I want to save all the results for UVW0 in a file bu my current program only saves the last results of the calculation in the mat file.
How can I save all the results for each calculation in the mat file?
Many thanks in advance!

채택된 답변

Stephen23
Stephen23 2023년 2월 22일
편집: Stephen23 2023년 2월 22일
"How can I save all the results for each calculation in the mat file?"
The standard, efficient, simple approach is to store the data in one array and save it once after the loop.
But why do you need a loop anyway? That calculation is easy to perform without a loop:
V = 31:1:61; % got rid of the superfluous square brackets too
angle = 2;
UVW0 = V .* [cos(angle);0;sin(angle)]
UVW0 = 3×31
-12.9006 -13.3167 -13.7328 -14.1490 -14.5651 -14.9813 -15.3974 -15.8136 -16.2297 -16.6459 -17.0620 -17.4782 -17.8943 -18.3105 -18.7266 -19.1428 -19.5589 -19.9750 -20.3912 -20.8073 -21.2235 -21.6396 -22.0558 -22.4719 -22.8881 -23.3042 -23.7204 -24.1365 -24.5527 -24.9688 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28.1882 29.0975 30.0068 30.9161 31.8254 32.7347 33.6440 34.5533 35.4626 36.3719 37.2812 38.1905 39.0998 40.0091 40.9184 41.8277 42.7370 43.6463 44.5556 45.4649 46.3742 47.2835 48.1928 49.1021 50.0114 50.9207 51.8300 52.7393 53.6485 54.5578
save myresults.mat UVW0
  댓글 수: 1
Joe
Joe 2023년 2월 22일
Thanks a lot!
I used the loop to calculate V*cos(angle) for each element of V from 31 to 61.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by