Printing and Plotting after each loop

I have a for loop where the structure is like this
A=[1 3 4;3 5 6]
U=[]
for i=1:10
...
U=A
end
how would I print U matirx after each loop on the text file beacause when I am doing that only the matirx in the 10th iteration loop prints and how would I be able to plot all those iterations in one figure using point clouds?

댓글 수: 3

It seems to print all the iterations to me
A=[1 3 4;3 5 6]
A = 2×3
1 3 4 3 5 6
U=[]
U = []
for i=1:10
A = A * 2;
U=A
end
U = 2×3
2 6 8 6 10 12
U = 2×3
4 12 16 12 20 24
U = 2×3
8 24 32 24 40 48
U = 2×3
16 48 64 48 80 96
U = 2×3
32 96 128 96 160 192
U = 2×3
64 192 256 192 320 384
U = 2×3
128 384 512 384 640 768
U = 2×3
256 768 1024 768 1280 1536
U = 2×3
512 1536 2048 1536 2560 3072
U = 2×3
1024 3072 4096 3072 5120 6144
Michael
Michael 2021년 3월 3일
Do you want it to print to a file or the command window?
A
A 2021년 3월 3일
I want to print it to a text file

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

 채택된 답변

Walter Roberson
Walter Roberson 2021년 3월 4일

0 개 추천

A=[1 3 4;3 5 6]
A = 2×3
1 3 4 3 5 6
U=[]
U = []
for i=1:10
A = A * 2;
U=A;
dlmwrite('U.txt', U, '-append')
end
!cat U.txt
2,6,8 6,10,12 4,12,16 12,20,24 8,24,32 24,40,48 16,48,64 48,80,96 32,96,128 96,160,192 64,192,256 192,320,384 128,384,512 384,640,768 256,768,1024 768,1280,1536 512,1536,2048 1536,2560,3072 1024,3072,4096 3072,5120,6144

댓글 수: 3

A
A 2021년 3월 4일
편집: A 2021년 3월 4일
Thanks a lot! Do you know how to create a space between each iteration? For instance:
2,6,8
6,10,12
4,12,16
12,20,24
A=[1 3 4;3 5 6]
A = 2×3
1 3 4 3 5 6
U=[]
U = []
for i=1:10
A = A * 2;
U=A;
dlmwrite('U.txt', U, '-append')
dlmwrite('U.txt', ' ', '-append')
end
!cat U.txt
2,6,8 6,10,12 4,12,16 12,20,24 8,24,32 24,40,48 16,48,64 48,80,96 32,96,128 96,160,192 64,192,256 192,320,384 128,384,512 384,640,768 256,768,1024 768,1280,1536 512,1536,2048 1536,2560,3072 1024,3072,4096 3072,5120,6144
A
A 2021년 3월 6일
Thanks Alot!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

A
A
2021년 3월 3일

댓글:

A
A
2021년 3월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by