MATLAB: I have developed a gui with a plotting area , now the problem is i need to transfer the results of the calculation that are being used in plotting to be shown in the text file so can you suggest me how to do that on clicking the plot button.

guiplotpushbuttonresultstext filetransfer

i have developed a gui with a plotting area , now the problem is i need to transfer the results of the calculation that are being used in plotting to be shown in the text file so can you suggest me how to do that on clicking the plot button.

Best Answer

Your GUI button needs a callback that will be invoked whenever the user presses the button. If the button name is pushbutton1 then your GUI m file should have something like the following defined within it
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
In the body of this function you will plot the data (since you have called this the plot button) and write the data to file:
% plot the data
% open a text file
fid = fopen('fileToWriteTo.txt','w');
if fid>0
% write the data to file (this may require a loop given your data set)
fprintf(fid,'formatString',dataToWriteA,dataToWriteB, etc...);
% close the file
fclose(fid);
end
The formatString in the above describes the format of the data (integers, floats, strings, etc.) and the dataToWriteX is the data to write to file. In the command window type help fprintf or doc fprintf for details on how to use this function.