is there a way to go to the line above using fprintf function ?

8 次查看(过去 30 天)
I'm writing on a csv file and I'm writing column by column for example here :
for i = 1 : length(col)
fprintf( fid, '%s\n', matrix{i});
end
I used this to make new line after each iteration I need to go to the same place before entering the loop
for example the output after the loop in csv will be 1 22 33 45 6 8 9 I need the pointer to go back to element 1 because what I need to do is to make another column near this column does anyone know how to do this?
Thank you

回答(1 个)

Diwakar
Diwakar 2018-7-13
编辑:Diwakar 2018-7-13
Okay so your idea is to move the cursor to a different part of your file after a write job. So, for this I would suggest you to look into the ftell function of MATLAB. The link to the documentation is : https://www.mathworks.com/help/matlab/ref/ftell.html?searchHighlight=ftell&s_tid=doc_srchtitle
This function will give you the current location of the cursor after the first write. Then you can use the fseek function to move the cursor to the desired location. The documentation for which is : https://www.mathworks.com/help/matlab/ref/fseek.html?searchHighlight=ftell&s_tid=doc_srchtitle
Hope this helps Cheers!

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by