How to "save as" a processed graph as a .txt data file?

조회 수: 3 (최근 30일)
Ekin
Ekin 2013년 8월 28일
I can read and obtain graph from a data file (.txt) with my GUI code. With some functions(noise removal, clipping etc.), i change the graph (so as data)and now i want to "save as" the processed data into another .txt file (i will create) with a button. Is there any way to do this?
My file opening code:
function uipushtool_ClickedCallback(hObject, eventdata, handles)
[filename1,filepath1]=uigetfile({'*.txt*','Text Files'},...
'Select Data File 1');
cd(filepath1);
fp= fopen(filename1);
fgets(fp);
A = textscan(fp, '%f');
fclose(fp);
result=A{:};
%Implementation of function here
axes(handles.axes3);
plot(result);
hold on;
After implementing the data, now with another button i want to save the new data file as another .txt file. Thanks in advance!

답변 (2개)

Iain
Iain 2013년 8월 28일
csvwrite can write text files (csv delimited), save can write text files if you use the ascii flag.
uiputfile is a function that lets your browse for a desired output filename.
You might prefer getting some mileage out of writing the data to excel format (xlswrite)
  댓글 수: 3
Iain
Iain 2013년 8월 28일
csvwrite('myfile.csv', result)
Ekin
Ekin 2013년 8월 28일
"finalresult" is defined in another function (below) how can i use it without defining? Here is the error:
Undefined function or variable 'result'.
Error in NoiseRemoval>pushbutton4_Callback (line 179)csvwrite('myfile.csv', finalresult)
function pushbutton4_Callback(hObject, eventdata, handles)
[filename1,filepath1]=uiputfile({'*.txt*','Text Files'},...
'Save New File');
csvwrite('myfile.csv', result)
% --------------------------------------------------------------------
function uipushtool1_ClickedCallback(hObject, eventdata, handles)
[filename1,filepath1]=uigetfile({'*.txt*','Text Files'},...
'Select Data File 1');
cd(filepath1);
fp= fopen(filename1);
fgets(fp);
A = textscan(fp, '%f');
fclose(fp);
result=A{:};
%Some implementations
%lets say finalresult=result;
axes(handles.axes2);
plot(finalresult);
hold on;

댓글을 달려면 로그인하십시오.


David Sanchez
David Sanchez 2013년 8월 28일
If you put your data into a cell array, you can easily save it into a .txt file using dlmcell.m from fileexchange:
href = ""<http://www.mathworks.es/matlabcentral/fileexchange/25387-write-cell-array-to-text-file</a>>
  댓글 수: 1
Ekin
Ekin 2013년 8월 28일
The data file is (n,1) matrix, n varies as data file changes.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by