how to save data from for loop in a matrix ??

조회 수: 1 (최근 30일)
yasmeen hadadd
yasmeen hadadd 2016년 9월 26일
답변: Thorsten 2016년 9월 26일
Hello;
How i can save all values that i calculated from the for loop in a new matrix , but i have in the last loop one value ??? thanks

답변 (2개)

Thorsten
Thorsten 2016년 9월 26일
for i=1:10; a(i)=i+5; end

KSSV
KSSV 2016년 9월 26일
It depends on how your code is.
You may see the below example, where I am saving the output into mat file in a loop .
clc; clear all ;
for i = 1:10
x=randn(1,1000);
out(i,:)=x.^2;
if i == 1
filename='myfile.mat';
save(filename,'out','-v7.3'); % save to MAT file
else
save(filename,'out','-append');
end
end
Note that out can be initialized knowing the loop. there are many other ways too to save the output.
  댓글 수: 1
yasmeen hadadd
yasmeen hadadd 2016년 9월 26일
No, you didn't understand me if i have this code for example:
clc;clear all;
for i=1:10; a=i+5; end
the final value of a =15 , i need a =[ 6 7 8 9 10 11 12 13 14 15];
thanks

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by