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
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sumera Yamin
am 14 Aug. 2018
Kommentiert: Adam Danz
am 16 Aug. 2018
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)
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 14 Aug. 2018
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 Kommentare
Adam Danz
am 16 Aug. 2018
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
am 16 Aug. 2018
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';
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!