Saving cell array data from uitable using 'save'

1 次查看(过去 30 天)
I have the data from a uitable as:
inputdata =
'300' [101.0366] [0.7744] [0.3806]
'600' [101.2867] [0.4358] [0.1959]
'1000' [101.2317] [0.4522] [0.1898]
'2000' [101.4917] [0.5007] [0.2892]
'4000' [101.6842] [0.6338] [0.4064]
I am trying to save to a text file, but the following doesn't work.
inputdata=(get(handles.uitableDark,'Data'))
save('C\:DarkFPN.txt','inputdata','-ascii');

采纳的回答

Geoff Hayes
Geoff Hayes 2016-6-4
Jason - since inputdata is a cell array, I suspect that you are observing the following error
Warning: Attempt to write an unsupported data type to an ASCII file.
Variable 'inputdata' not written to file.
Is this is true, what can you tell us about your data from the uitable. Your example has a mix of numeric datatype and character arrays (the first column). Can you convert this first column to doubles and so have a matrix all of the same data type? If so, then you will be able to use the above save function.
If not, then I would use the example from export cell array to text file which uses fprintf to write the data to file. Something like
fid = fopen('myData.txt','w');
if fid > 0
[nrows,ncols] = size(inputdata);
for row = 1:nrows
fprintf(fid,'%s %f %f %f\n',inputdata{row,:});
end
fclose(fid);
end
Try the above and see what happens!
  3 个评论
Jason
Jason 2016-6-6
I had to use 'wt' and not 'w' to get the newline character to work
fid = fopen('myData.txt','wt');
Geoff Hayes
Geoff Hayes 2016-6-6
I wondered about that. When I tried, I didn't need the text specifier. (R2014a, Mac OS)

请先登录,再进行评论。

更多回答(0 个)

类别

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