Saving a uitable to text file with variable number of columns
1 次查看(过去 30 天)
显示 更早的评论
Hi. I have a uitable that I populate with a variety of functions, each one has a different number of columns and colnames. I want to have a generic save function that will save regardless of the columns, and one where I can add the column names as a variable. This is my fixed column name approach. How do i adapt this for variable columns and column names.
%Save UI Table
tabledata = num2str(get(handles.uitable1,'data'));
fpath=get(handles.edit1,'String'); %get filepath from edit box
fname=get(handles.textFile,'String'); %get file name
ffull=[fpath,fname];
filename = 'C:\Output.txt';
fid = fopen(filename, 'w');
fprintf(fid, '%s\r\n', ffull);
rows=length(tabledata);
fprintf(fid,' %s %s %s %s %s %s %s\t\r\n', 'mean','mode','max','min','sd','min20','Dyn Range') %this part I want to be variable!!!!
for i = 1:rows
%tabledata(i,:)
% fprintf(fid, '%s\t %s\t %s\t %s\t %s\t %s\t %s\t \n', tabledata(i,:));
fprintf(fid, '%s\r\n', tabledata(i,:));
% fprintf(fid, '\r\n')
end
fclose(fid);
I also need to add that my table consists ofa mixture of strings and numbers by using a cell array.
0 个评论
采纳的回答
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!