hi ! i am developing a gui that basically takes input from the interface processes some calculation and generated graph of the calculated data with the trigerring of push button
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
rohith adulla
am 20 Jun. 2014
Kommentiert: Geoff Hayes
am 24 Jun. 2014
the thing is i am successful till date on the project now im stuck with this small problem, like i am doing some calculations and generating values right, i want to transfer these values to a text file , i tried the below code and mentioned the path of the text file
text_file_name='experiment.txt'; full_path=strcat('C:/Users/r_a192/Desktop/',text_file_name); fid = fopen(full_path,'wt'); fprintf(fid,'thetha value genrated is %f and frequency genrated is %f ',theta,fm); fclose(fid); [fid,msg] = fopen(full_path,'wt'); if(fid == -1) error(msg)
is this correct ?? do i need to make changes??i am not able to get any result, please help me i am not able to solve the problem
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 20 Jun. 2014
Rohith - it is not all that clear from your question what the problem is. Is the file being generated with no data? Is the file being generated with invalid data? Or is the file not being generated at all?
Please try the following:
text_file_name='experiment.txt';
directory_name='C:/Users/r_a192/Desktop';
full_path = fullfile(directory_name,text_file_name);
% open the file for writing (w) in text mode (t)
fid = fopen(full_path,'wt');
if fid<0
error(['Could not open file ' full_path]);
else
fprintf(fid,'thetha value genrated is %f and frequency genrated is %f\n',theta,fm);
fclose(fid);
end
Don't call the [fid,msg] = fopen(full_path,'wt'); again else it will overwrite the contents of the file.
If you want to append the results to the file (and so not lose the previous results), then change the fopen permission mode to append (a)
fid = fopen(full_path,'at');
Try the above and see what happens!
10 Kommentare
Geoff Hayes
am 24 Jun. 2014
Rohith - you still haven't answered my question - what do you mean by the step is inactive? If you do not know how to use the debugger then use the link that I provided in my previous comment. Being able to debug in MATLAB is an incredibly useful skill. You should take the time to learn how to do this.
I glanced at your code, and as soon as I pressed the Plot button, the software crashed at the line
set(h,'LineWidth',30)
because there is no h handle. I think that this should instead be
set(handles.axes1,'LineWidth',30);
As well, at the line of code where theta is calculated, rather than using
theta = atand(Frx/Fry);
you should probably use
theta = atan2d(Frx,Fry);
to avoid the division by zero for the case where Fry is zero (which, currently, means that theta is NaN).
I put a breakpoint at the line where the 'experiment.txt' file is created and then stepped through the code to see if data is being written to this line. Once I stepped past the line fclose(fid);, I opened the file (which was now created in the specified directory) and observed the following text
thetha value genrated is NaN and frequency genrated is 0.000000
So the writing to file does work.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!