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

6 views (last 30 days)
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

Answers (1)

Diwakar
Diwakar on 13 Jul 2018
Edited: Diwakar on 13 Jul 2018
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!

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!