It needs to be like this:
Iteration # MaxError Row Column 1 er(1) er(2) er(3) 2 er(1) er(2) er(3) 3 er(1) er(2) er(3) 4 er(1) er(2) er(3) 5 er(1) er(2) er(3)
the formatting isnt staying
i need a column with iteration number values will come from loop index i need a column with "max error" values will come from a spot in a matrix then two more columns essentially the same as the above one.
er is a 1x3 matrix im guessing i can get the iteration number from the for loop index please be as explcit as possible, I know almost nothing about MATLAB.
this is what i have so far its giving me an error with fopen V is just a dummy variable im using to test. real one will also be a 1X3 matrix
fid = fopen('c:\\error.txt','wt'); V=[1 3 5] for x=1:10 fprintf(fid,'%f',x,V(1),V(2),V(3)); V=V*2 end
No products are associated with this question.
Does the fprintf work enough to get you your header? If you can get that and the rest of the output is just numbers i would suggest using dlmwrite.
for iteration=1:numberofiterations tobewritten = [iteration er]; %build the row dlmwrite([folderpath, filename],tobewritten,'-append'); %append the tobewritten data to the end of the file. end
look at the documentation for dlmwrite but you'll still need to use fprintf to get your header and close the file before you dlmwrite. Hope that helps
OK, good to post your try...do try to format it for legibility though--put a blank line and two blank spaces in front of the first code line. Look at the preview window until it looks legible...
OK, fair start...consider the following similar example--
V=rand(5,3); % some dummy data fmt=[repmat('%8.3f',1,size(V,2)) '\n']; % fixed-width w/ right #/line fprintf(fid,fmt,V.')
To write the header, use a counted '%s' field for each column to align them properly.
Read up on the use of formatting strings in detail in the doc for fprintf
Forgot about you wanting the index row, too, sorry...
fmt=[repmat('%8.3f',1,size(V,2)+1) '\n']; % right #/line including counter fprintf(fid,fmt,[(1:size(V,1)).' V].')
Just prepend the vector [1:size(V,1)].' to the array. NB: the .' on the overall to account for column-major storage order in Matlab. If you don't follow that, try it w/o the last ".'" transpose and see what happens instead.