is it possible to save csv files in loop with fopen..getting error Error using fopen Invalid permission.

4 views (last 30 days)
for k=1:38
Column_1_t=(1:1000)*0.00008
Column_2_output = cellstr(num2str(Y{k}.OutputData));
mag = Y{k}.OutputData;
% change name here to write
% change name here to write
savedfile = folder_name;
fid_out(k) = fopen(num2str(k),'savedfile_.csv','w'); %open file and create fid %here i am getting error
%save tab-separated column headers
%define column format and names and save to file
fprintf(fid_out(k),'%s%s%s\n','time',',','Cal');
fprintf(fid_out(k),'%s%s%s\n','(ms)',',','(V)');
fprintf(fid_out(k),'\n');
%save tab-separated columns of data
for i = 1:size(data,1) %loop trough each line of each data variable and save to file line by line
%define column format and date to be saved.
%use () for numeric data, and {} for strings
fprintf(fid_out(k),'%0.8f%s%0.8f\n',data(i,1),',',data(i,2));
end
fclose(fid_out(k))
end

Accepted Answer

Star Strider
Star Strider on 2 Nov 2019
It would be easier to use csvwrite (or writematrix) than creating you own version.
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!