i need help in matlab gui for the following code

Frx = calculation
Fry = calculation
Fm = sqrt((Frx)^2+(Fry)^2);
theta = atand(Frx/Fry);
compass(handles.axes1,theta,Fm);
now the thing i need is, i want the values Fm and Theta to be stored in a text file so how do i do that i tried the below code but was not able to get the output
text_file_name='experiment.txt';
full_path=strcat('C:/Users/xyz/Desktop/',experiment);
fid = fopen(full_path,'wt');
fprintf(fid,'thetha value genrated is %f and frequency genrated is %f ',theta,fm);
fclose(fid);

回答 (2 件)

Star Strider
Star Strider 2014 年 6 月 13 日

1 投票

One problem is that you defined Fm here as:
Fm = sqrt((Frx)^2+(Fry)^2);
but in your fprintf statement, you refer to it as fm instead:
fprintf(fid,'thetha value genrated is %f and frequency genrated is %f ',theta,fm);
MATLAB is case-sensitive, so Fm~=fm.
Change it to:
fprintf(fid,'thetha value genrated is %f and frequency genrated is %f ',theta,Fm);
and see if that works.

4 件のコメント

rohith  adulla
rohith adulla 2014 年 6 月 13 日
thank you i changed it long back but after doing all these also i am not able to update the text file which i specified in the path mentioned
Star Strider
Star Strider 2014 年 6 月 13 日
Another problem I just now found is that ‘experiment’ does not exist as a variable in the code you posted.
Assuming you intend the file name to be that assigned in ‘text_file_name’, change your ‘full_path’ assignment to:
full_path=strcat('C:/Users/xyz/Desktop/',text_file_name);
and see if that works.
Image Analyst
Image Analyst 2014 年 6 月 13 日
Or use fullfile(), the function meant for that:
full_path = fullfile('C:/Users/xyz/Desktop/', text_file_name);
Star Strider
Star Strider 2014 年 6 月 13 日
One other thing just now occurred to me. Are you running Linux or Windows? I assumed you are running Linux because of the forward-slants ‘/’ in your path. If you are running Windows, it should be (borrowing Image Analyst’s preferred construction):
full_path = fullfile('C:\Users\xyz\Desktop\', text_file_name);
If you are running Windows, try that. If Linux, ignore it.
Sara
Sara 2014 年 6 月 13 日

0 投票

In this part, I think you meant to do:
full_path=strcat('C:/Users/xyz/Desktop/',text_file_name);
Also, do:
[fid,msg] = fopen(full_path,'wt');
if(fid == -1),error(msg),end
so you will see if there was an error in opening the file.
Did you get any specific error that the code above did not solve?

3 件のコメント

rohith  adulla
rohith adulla 2014 年 6 月 13 日
i tried what you told there is no change
Sara
Sara 2014 年 6 月 13 日
Do you get any error in the writing? What do you get if after the writing you do:
[fid,msg] = fopen(full_path,'r');
if(fid == -1),error(msg),end
fgetl(fid)
rohith  adulla
rohith adulla 2014 年 6 月 13 日
nope

この質問は閉じられています。

質問済み:

2014 年 6 月 13 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by