new girl needs a little help with fprintf and loopies
显示 更早的评论
can somebody please help me
i am VERY VERY new to matlab, but i'm trying to learn it.
i've written a script that uses a couple of "for loops" to produce several "blocks" of data, like a hundred seventy five or more blocks (only a couple blocks are shown below). when I run the script all hundred seventy or so go across my command window, but that's not what ends up in my output file. only the last block of data ends up in my output file, and i need them all in the file.
so here's an example of the output file
1 3.23 -422 21.1
1 3.25 -124 45.0
1 2.99 -378 33.3
2 3.12 -601 61.0
2 3.22 -227 41.7
2 4.02 -327 32.9
3 2.70 -129 61.8
3 1.91 -304 65.2
3 0.99 -198 63.6
.
.
.
175 7.32 -201 111.0
175 6.25 -287 101.7
175 8.02 -327 135.2
and here's the stuff I use to write the data to a file
fid = fopen('output_file.dat', 'wt')
data_to_print = [block_number data_A data_B data_C]
fprintf(fid, '%d %0.6f %d %0.6f' data_to_print)
but all i get is the last block in my output file :(
175, 7.32, -201, 111.0
175, 6.25, -287, 101.7
175, 8.02, -327, 135.2
can one of you guys please help me learn how to write all the blocks of data into the file?
thanks so much Tabby
采纳的回答
更多回答(1 个)
Azzi Abdelmalek
2013-9-3
编辑:Azzi Abdelmalek
2013-9-3
Your for loop should be inside {fopen fclose}
fopen
%your for loop
fclose
类别
在 帮助中心 和 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!