Dear All, I am new to MATLAb GUI and want to create one. My program should work in the following sequence. 1) Select option of polarity from a pop-up menu (total two options are available) 2) load file according to polarity selected 3) execute part

1 次查看(过去 30 天)
My Matlab script is as follows (which works perfectly but i have to change it to GUI for user readiness)
R_pp=[]; Vf_pp=[];
for i=1:Nmeas_pp
Vf_pp=vertcat(Vf_pp,x_pp(i),y_pp(i));
k=B_pp(i)/(2*rigidity); % m^(-1)
M11_pp=cos(k*l)^2*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)) + k*sin(k*l)^2*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) - cos(k*l)*sin(k*l)*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2) - k*cos(k*l)*sin(k*l)*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k);
M12_pp=cos(k*l)^2*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) - cos(k*l)*sin(k*l)*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) - (sin(k*l)^2*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2))/k + (cos(k*l)*sin(k*l)*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)))/k;
M13_pp=cos(k*l)^2*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2) - k*sin(k*l)^2*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) + cos(k*l)*sin(k*l)*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)) - k*cos(k*l)*sin(k*l)*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l));
M14_pp=cos(k*l)^2*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) + cos(k*l)*sin(k*l)*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) + (sin(k*l)^2*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)))/k + (cos(k*l)*sin(k*l)*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2))/k;
M31_pp=k*sin(k*l)^2*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) - cos(k*l)^2*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2) - cos(k*l)*sin(k*l)*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)) + k*cos(k*l)*sin(k*l)*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l));
M32_pp= -cos(k*l)^2*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) - cos(k*l)*sin(k*l)*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) - (sin(k*l)^2*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)))/k - (cos(k*l)*sin(k*l)*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2))/k;
M33_pp=cos(k*l)^2*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)) + k*sin(k*l)^2*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) - cos(k*l)*sin(k*l)*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2) - k*cos(k*l)*sin(k*l)*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k);
M34_pp=cos(k*l)^2*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) - cos(k*l)*sin(k*l)*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) - (sin(k*l)^2*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2))/k + (cos(k*l)*sin(k*l)*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)))/k;
Rlinex_pp= [M11_pp, M12_pp, M13_pp, M14_pp];
Rliney_pp= [M31_pp, M32_pp, M33_pp, M34_pp];
R_pp=vertcat(R_pp,Rlinex_pp,Rliney_pp);
end
R_mp=[];
Vf_mp=[];
for i=1:Nmeas_mp
Vf_mp=vertcat(Vf_mp,x_mp(i),y_mp(i));
k=B_mp(i)/(2*rigidity); % m^(-1)
M11_mp=cos(k*l)^2*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)) - k*sin(k*l)^2*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) + cos(k*l)*sin(k*l)*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2) - k*cos(k*l)*sin(k*l)*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k);
M12_mp=cos(k*l)^2*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) + cos(k*l)*sin(k*l)*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) + (sin(k*l)^2*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2))/k + (cos(k*l)*sin(k*l)*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)))/k;
M13_mp=cos(k*l)^2*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2) + k*sin(k*l)^2*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) - cos(k*l)*sin(k*l)*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)) - k*cos(k*l)*sin(k*l)*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l));
M14_mp=cos(k*l)^2*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) - cos(k*l)*sin(k*l)*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) - (sin(k*l)^2*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)))/k + (cos(k*l)*sin(k*l)*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2))/k;
M31_mp=cos(k*l)*sin(k*l)*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)) - k*sin(k*l)^2*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) - cos(k*l)^2*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2) + k*cos(k*l)*sin(k*l)*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l));
M32_mp=cos(k*l)*sin(k*l)*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) - cos(k*l)^2*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) + (sin(k*l)^2*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)))/k - (cos(k*l)*sin(k*l)*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2))/k;
M33_mp=cos(k*l)^2*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)) - k*sin(k*l)^2*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) + cos(k*l)*sin(k*l)*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2) - k*cos(k*l)*sin(k*l)*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k);
M34_mp=cos(k*l)^2*(D*cos(k*l)^2 + (cos(k*l)*sin(k*l))/k) + cos(k*l)*sin(k*l)*(sin(k*l)^2/k + D*cos(k*l)*sin(k*l)) + (sin(k*l)^2*(cos(k*l)*sin(k*l) - D*k*sin(k*l)^2))/k + (cos(k*l)*sin(k*l)*(cos(k*l)^2 - D*k*cos(k*l)*sin(k*l)))/k;
Rlinex_mp= [M11_mp, M12_mp, M13_mp, M14_mp];
Rliney_mp= [M31_mp, M32_mp, M33_mp, M34_mp];
R_mp=vertcat(R_mp,Rlinex_mp,Rliney_mp);
end
lsqr(R_pp, Vf_pp)
lsqr(R_mp, Vf_mp)

采纳的回答

Adam Danz
Adam Danz 2018-8-14
Hello Sumera,
If you've already got the code, the hard part is done :) To start with the GUI, I'll recommend using guide().
From matlab command window, run
guide
which will open a window. Select the "Create new GUI' tab, the select "Blank GUI", then "OK" button. This will open an untitled figure where you can drag and drop GUI components and design your GUI. Hover your mouse over the GUI components on the left to see what they are. You'll see pop-up Menu and others. Once you drag them to the figure space, right click on the component and open "property inspector". Here you'll have all of the options available for that component. You can search for answers on google or within this forum to learn about those options.
When you save the figure it will produce code with callback functions etc. If you get stuck, feel free to ask follow-up questions.
  6 个评论
Adam Danz
Adam Danz 2018-8-16
help sprintf
sptrinf() formats numbers.
pi = 3.141592653.... but I only want to display the first 2 decimal places. Run that line of code to see the result.
The '\n' part of the 2nd example makes a new row of text. Run that line to see the result.
Adam Danz
Adam Danz 2018-8-16
Question copied here: Hi, but how would i link the result of my code in .m file (lsqr(R_pp, Vf_pp) in my original code) to the GUI?
You have to use the handle to the object. In my code above, 'edit1' is the handle to the object. If you're using GUIDE, use the 'handles' structure.
handles.edit1.String = 'blah';

请先登录,再进行评论。

更多回答(1 个)

Sumera Yamin
Sumera Yamin 2018-8-16
Thank you very much for the clarification.

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by