Saving a uitable contents for any number of columns.
    7 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I have the following code to save the contents of a uitable but for a fixed number of columns. How can I make it generic so it will work with any number of columns?
inputdata=(get(handles.uitableDark,'Data'))
%inputdata=cell2mat(inputdata)
[name,path] = uiputfile('C:\DarkFPN.txt','Save file name');
file=fullfile(path,name)
%save(file,'inputdata','-ascii');
fid = fopen(file,'wt');
 if fid > 0
     [nrows,ncols] = size(inputdata);
     for row = 1:nrows
         inputdata{row,:}
         fprintf(fid,'%.0f %.2f %.2f %.2f %.2f\n',inputdata{row,:});
     end
     fclose(fid);
 end
Thanks
Jason
0 件のコメント
採用された回答
  Brandon Eidson
    
 2017 年 3 月 16 日
        
      編集済み: Brandon Eidson
    
 2017 年 3 月 16 日
  
      Hey Jason, assuming your various-column-numbered files have a repeatable format, you can create the FORMAT string based on your number of columns like in the code below.
[nrows, ncols] = size(inputdata);
formatString = '%.0f';
for col = 2:ncols
    formatString = strcat(formatString, ' %.2f');
end
formatString = strcat(formatString, '\n');
Then you can pass "formatString" as an argument to the "fprintf" function.
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

