Saving cell array data from uitable using 'save'

7 Ansichten (letzte 30 Tage)
Jason
Jason am 4 Jun. 2016
Kommentiert: Geoff Hayes am 6 Jun. 2016
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');

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 4 Jun. 2016
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 Kommentare
Jason
Jason am 6 Jun. 2016
I had to use 'wt' and not 'w' to get the newline character to work
fid = fopen('myData.txt','wt');
Geoff Hayes
Geoff Hayes am 6 Jun. 2016
I wondered about that. When I tried, I didn't need the text specifier. (R2014a, Mac OS)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by