Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.14 KB | None | 0 0
  1. % This is the MagFieldMeas which is used to measure magnetic field with the
  2. % LakeShore Gaussmeter, and Velmex stepping motors.
  3. %
  4. % This was last updated July 15th 2019 by Devin Morin
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6.  
  7. function MagFieldMeas(o1,o2)
  8.  
  9.  
  10. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  11. % The program is broken up into two main parts. The first part is the UI
  12. % elements, which are contained in one function. The second part is the
  13. % logic and measurement/motor section that will look at inputs into the
  14. % UI elements for direction.
  15. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16.  
  17. global hp pb cb eb tb ax
  18. global xyE zE s1 s2 L
  19. if nargin ==0
  20. close all
  21. scrsz = get(0,'ScreenSize');
  22. scrsz(4)=scrsz(4)-60;
  23. figure('NumberTitle','off','Name',...
  24. 'Magnetic Field Measurement','position',scrsz);
  25. %% 1D Measurement UI
  26. hp(1)= uipanel('Title','1D Measurement','FontSize',12,'units',...
  27. 'normalized','Position',[0.01 0.74 1/4 .09 ]);
  28. cb(1) = uicontrol('parent',hp(1),'Style', 'check','units','normalized',...
  29. 'String','X','Position',[0 0.5 1/5 .6],'value',0,'fontsize',13,'Callback','MagFieldMeas(1,1)');
  30. cb(2) = uicontrol('parent',hp(1),'Style', 'check','units','normalized',...
  31. 'String','Y','Position',[2/5 .5 1/5 .6],'value',0,'fontsize',13,'Callback','MagFieldMeas(1,2)');
  32. cb(3) = uicontrol('parent',hp(1),'Style', 'check','units','normalized',...
  33. 'String','Z','Position',[4/5 .5 1/5 .6],'value',1,'fontsize',13,'Callback','MagFieldMeas(1,3)');
  34.  
  35. tb(1) = uicontrol('parent',hp(1),'Style', 'text','units','normalized',...
  36. 'String','Z+','Position',[0 .2 1/5 .4],'value',1,'fontsize',13,'Callback','');
  37. tb(2) = uicontrol('parent',hp(1),'Style', 'text','units','normalized',...
  38. 'String','Z-','Position',[2/4 .2 1/5 .4],'value',1,'fontsize',13,'Callback','');
  39.  
  40. eb(1) = uicontrol('parent',hp(1),'Style', 'edit','units','normalized',...
  41. 'String','0','Position',[1/4 .2 1/5 .4],'value',1,'fontsize',13,'Callback','');
  42. eb(2) = uicontrol('parent',hp(1),'Style', 'edit','units','normalized',...
  43. 'String','5','Position',[3/4 .2 1/5 .4],'value',1,'fontsize',13,'Callback','');
  44. %% 2D Measurement UI
  45. hp(2)= uipanel('Title','2D Measurement','FontSize',12,'units',...
  46. 'normalized','Position',[0.01 0.585 1/4 .15]);
  47. cb(4) = uicontrol('parent',hp(2),'Style', 'check','units','normalized',...
  48. 'String','XY','Position',[0 .8 1/5 .15],'value',1,'fontsize',13,'Callback','MagFieldMeas(2,1)');
  49. cb(5) = uicontrol('parent',hp(2),'Style', 'check','units','normalized',...
  50. 'String','YZ','Position',[2/5 .8 1/5 .15],'value',0,'fontsize',13,'Callback','MagFieldMeas(2,2)');
  51. cb(6) = uicontrol('parent',hp(2),'Style', 'check','units','normalized',...
  52. 'String','ZX','Position',[4/5 .8 1/5 .15],'value',0,'fontsize',13,'Callback','MagFieldMeas(2,3)');
  53.  
  54.  
  55.  
  56. tb(3) = uicontrol('parent',hp(2),'Style', 'text','units','normalized',...
  57. 'String','X min','Position',[0 .25 1/5 .3],'value',1,'fontsize',13,'Callback','');
  58. tb(4) = uicontrol('parent',hp(2),'Style', 'text','units','normalized',...
  59. 'String','X max','Position',[2/4 .25 1/5 .3],'value',1,'fontsize',13,'Callback','');
  60. tb(5) = uicontrol('parent',hp(2),'Style', 'text','units','normalized',...
  61. 'String','Y min','Position',[0 0 1/5 .3],'value',1,'fontsize',13,'Callback','');
  62. tb(6) = uicontrol('parent',hp(2),'Style', 'text','units','normalized',...
  63. 'String','Y max','Position',[2/4 0 1/5 .3],'value',1,'fontsize',13,'Callback','');
  64.  
  65. eb(3) = uicontrol('parent',hp(2),'Style', 'edit','units','normalized',...
  66. 'String','-2','Position',[1/4 .4 1/5 .2],'value',1,'fontsize',13,'Callback','');
  67. eb(4) = uicontrol('parent',hp(2),'Style', 'edit','units','normalized',...
  68. 'String','2','Position',[3/4 .4 1/5 .2],'value',1,'fontsize',13,'Callback','');
  69. eb(5) = uicontrol('parent',hp(2),'Style', 'edit','units','normalized',...
  70. 'String','0','Position',[1/4 0.05 1/5 .2],'value',1,'fontsize',13,'Callback','');
  71. eb(6) = uicontrol('parent',hp(2),'Style', 'edit','units','normalized',...
  72. 'String','5','Position',[3/4 0.05 1/5 .2],'value',1,'fontsize',13,'Callback','');
  73. %% Data UI
  74. hp(3)= uipanel('Title','Data','FontSize',12,'units',...
  75. 'normalized','Position',[0.01 0.835 1/4 .16 ]);
  76.  
  77. tb(7) = uicontrol('parent',hp(3),'Style', 'text','units','normalized',...
  78. 'String','Move (cm)','Position',[0 0.8 1/3 .2],'fontsize',13,'Callback','');
  79. tb(8) = uicontrol('parent',hp(3),'Style', 'text','units','normalized',...
  80. 'String','Averages','Position',[1/3 .8 1/3 .2],'fontsize',13,'Callback','');
  81. tb(9) = uicontrol('parent',hp(3),'Style', 'text','units','normalized',...
  82. 'String','Axis','Position',[2/3 .8 1/3 .2],'fontsize',13,'Callback','');
  83.  
  84. eb(7) = uicontrol('parent',hp(3),'Style', 'edit','units','normalized',...
  85. 'String','0.1','Position',[0.05 .55 1/5 0.2],'value',1,'fontsize',13,'Callback','');
  86. eb(8) = uicontrol('parent',hp(3),'Style', 'edit','units','normalized',...
  87. 'String','1','Position',[0.4 .55 1/5 .2],'value',1,'fontsize',13,'Callback','');
  88.  
  89.  
  90. cb(7) = uicontrol('parent',hp(3),'Style', 'check','units','normalized',...
  91. 'String','X','Position',[4/5 0.6 1/5 .15],'value',0,'fontsize',13,'Callback','MagFieldMeas(3,1)');
  92. cb(8) = uicontrol('parent',hp(3),'Style', 'check','units','normalized',...
  93. 'String','Y','Position',[4/5 0.4 1/5 .15],'value',0,'fontsize',13,'Callback','MagFieldMeas(3,2)');
  94. cb(9) = uicontrol('parent',hp(3),'Style', 'check','units','normalized',...
  95. 'String','Z','Position',[4/5 0.2 1/5 .15],'value',1,'fontsize',13,'Callback','MagFieldMeas(3,3)');
  96.  
  97. pb(1) = uicontrol('parent',hp(3),'Style', 'push','units','normalized',...
  98. 'String','Move','Position',[0.15 0.19 1/3 .3],'fontsize',13,'Callback','MagFieldMeas(1)');
  99. %% Run UI
  100.  
  101. hp(4)= uipanel('Title','','FontSize',12,'units',...
  102. 'normalized','Position',[0.01 0.05 0.2 .1 ]);
  103. pb(2) = uicontrol('parent',hp(4),'Style', 'push','units','normalized',...
  104. 'String','Run 1D/2D','Position',[0 0 1/2 1],'fontsize',13,'Callback','MagFieldMeas(2)');
  105. pb(3) = uicontrol('parent',hp(4),'Style', 'push','units','normalized',...
  106. 'String','Run 3D','Position',[1/2 0 1/2 1],'fontsize',13,'Callback','MagFieldMeas(4,4)');
  107. %% 3D Plotting UI
  108. hp(6)= uipanel('Title','3D Measurement','FontSize',12,'units',...
  109. 'normalized','Position',[0.01 0.38 0.25 0.2]);
  110.  
  111.  
  112. tb(11) = uicontrol('parent',hp(6),'Style', 'text','units','normalized',...
  113. 'String','Y min','Position',[0 .25 1/5 .3],'value',1,'fontsize',13,'Callback','');
  114. tb(12) = uicontrol('parent',hp(6),'Style', 'text','units','normalized',...
  115. 'String','Y max','Position',[2/4 .25 1/5 .3],'value',1,'fontsize',13,'Callback','');
  116. tb(13) = uicontrol('parent',hp(6),'Style', 'text','units','normalized',...
  117. 'String','Z min','Position',[0 0 1/5 .3],'value',1,'fontsize',13,'Callback','');
  118. tb(14) = uicontrol('parent',hp(6),'Style', 'text','units','normalized',...
  119. 'String','Z max','Position',[2/4 0 1/5 .3],'value',1,'fontsize',13,'Callback','');
  120. tb(15) = uicontrol('parent',hp(6),'Style', 'text','units','normalized',...
  121. 'String','X min','Position',[0 0.6 1/5 .2],'value',1,'fontsize',13,'Callback','');
  122. tb(16) = uicontrol('parent',hp(6),'Style', 'text','units','normalized',...
  123. 'String','X max','Position',[2/4 0.6 1/5 .2],'value',1,'fontsize',13,'Callback','');
  124.  
  125.  
  126.  
  127. eb(10) = uicontrol('parent',hp(6),'Style', 'edit','units','normalized',...
  128. 'String','-2','Position',[1/4 .4 1/5 .15],'value',1,'fontsize',13,'Callback','');
  129. eb(11) = uicontrol('parent',hp(6),'Style', 'edit','units','normalized',...
  130. 'String','2','Position',[3/4 .4 1/5 .15],'value',1,'fontsize',13,'Callback','');
  131. eb(12) = uicontrol('parent',hp(6),'Style', 'edit','units','normalized',...
  132. 'String','0','Position',[1/4 0.15 1/5 .15],'value',1,'fontsize',13,'Callback','');
  133. eb(13) = uicontrol('parent',hp(6),'Style', 'edit','units','normalized',...
  134. 'String','5','Position',[3/4 0.15 1/5 .15],'value',1,'fontsize',13,'Callback','');
  135. eb(14) = uicontrol('parent',hp(6),'Style', 'edit','units','normalized',...
  136. 'String','0','Position',[1/4 0.65 1/5 .15],'value',1,'fontsize',13,'Callback','');
  137. eb(15) = uicontrol('parent',hp(6),'Style', 'edit','units','normalized',...
  138. 'String','5','Position',[3/4 0.65 1/5 .15],'value',1,'fontsize',13,'Callback','');
  139.  
  140. %% Increment Panel UI
  141. hp(5)= uipanel('Title','Probe','FontSize',12,'units',...
  142. 'normalized','Position',[0.01 0.247 0.25 .09 ]);
  143.  
  144. tb(10) = uicontrol('parent',hp(5),'Style', 'text','units','normalized',...
  145. 'String','Increment(cm)','Position',[0 0.7 0.4 .4],'fontsize',13,'Callback','');
  146. eb(9) = uicontrol('parent',hp(5),'Style', 'edit','units','normalized',...
  147. 'String','0.05','Position',[0.07 .2 0.2 .4],'value',1,'fontsize',13,'Callback','');
  148. cb(10) = uicontrol('parent',hp(5),'Style', 'check','units','normalized',...
  149. 'String','Remove SideToSide','Position',[0.4 0.4 0.6 .3],'value',1,'fontsize',13);
  150.  
  151.  
  152.  
  153. ax(1)=axes('position',[0.35 0.25 0.6 0.7]);
  154. set(gca,'linewidth',2,'box','on','FontSize',18)
  155. xlabel(ax(1),'X (cm)','FontSize',16)
  156. ylabel(ax(1),'Y (cm)','FontSize',16)
  157.  
  158.  
  159. set(cb(1:6),'enable','off')
  160. set(eb(1:6),'enable','off')
  161.  
  162. end
  163.  
  164. %% Allowing probe tip to be moved in X,Y,Z.
  165. if o1==3
  166. if o2==1
  167. set(cb(8),'value',0);
  168. set(cb(9),'value',0);
  169. end
  170. if o2==2
  171. set(cb(7),'value',0);
  172. set(cb(9),'value',0);
  173. end
  174. if o2==3
  175. set(cb(8),'value',0);
  176. set(cb(7),'value',0);
  177. end
  178. end
  179.  
  180. if nargin==1 && o1==1
  181. axx = get(cb(7),'value');
  182. axy = get(cb(8),'value');
  183. axz = get(cb(9),'value');
  184. Mh = str2double(get(eb(7),'string'));
  185. if axx == 1
  186. start
  187. movem(s2,1,Mh);
  188. stop
  189. end
  190. if axy == 1
  191. start
  192. movem(s2,2,Mh);
  193. stop
  194. end
  195. if axz == 1
  196. start
  197. movem(s2,3,Mh);
  198. stop
  199. end
  200. set(cb(1:6),'enable','on')
  201.  
  202. end
  203. %% Selecting the measurent
  204. % o1 and o2 values are determined by the check box inputs for XYZ
  205. % Changing a box value will recall the method and set the GUI accordingly
  206. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  207. if nargin == 2
  208. if o1==1 && o2 ==1
  209. set(cb(1),'value',1);
  210. set(cb(2:6),'value',0);
  211. set(tb(1),'String','X-');
  212. set(tb(2),'String','X+')
  213. set(eb(3:6),'enable','off')
  214. set(tb(3:6),'enable','off')
  215. set(eb(1:2),'enable','on')
  216. set(tb(1:2),'enable','on')
  217. xlabel(ax(1),'X (cm)','FontSize',16)
  218. ylabel(ax(1),'B_0 (G)','FontSize',16)
  219. L=1;
  220. elseif o1==1 && o2 ==2
  221. set(cb(1),'value',0)
  222. set(cb(2),'value',1)
  223. set(cb(3:6),'value',0)
  224. set(tb(1),'String','Y-')
  225. set(tb(2),'String','Y+')
  226. set(eb(3:6),'enable','off')
  227. set(tb(3:6),'enable','off')
  228. set(eb(1:2),'enable','on')
  229. set(tb(1:2),'enable','on')
  230. xlabel(ax(1),'Y (cm)','FontSize',16)
  231. ylabel(ax(1),'B_0 (G)','FontSize',16)
  232. L=2;
  233. elseif o1==1 && o2 ==3
  234. set(cb(1:2),'value',0)
  235. set(cb(3),'value',1)
  236. set(cb(4:6),'value',0)
  237. set(tb(1),'String','Z-');
  238. set(tb(2),'String','Z+')
  239. set(eb(3:6),'enable','off')
  240. set(tb(3:6),'enable','off')
  241. set(eb(1:2),'enable','on')
  242. set(tb(1:2),'enable','on')
  243. xlabel(ax(1),'Distance from the surface (cm)','FontSize',16)
  244. ylabel(ax(1),'B_0 (G)','FontSize',16)
  245. L=3;
  246. elseif o1==2 && o2 ==1
  247. set(cb(1:3),'value',0)
  248. set(cb(4),'value',1)
  249. set(cb(5:6),'value',0)
  250. set(eb(3:6),'enable','on')
  251. set(tb(3:6),'enable','on')
  252. set(eb(1:2),'enable','off')
  253. set(tb(1:2),'enable','off')
  254. set(tb(3),'String','X min')
  255. set(tb(4),'String','X max')
  256. set(tb(5),'String','Y min')
  257. set(tb(6),'String','Y max')
  258. xlabel(ax(1),'X (cm)','FontSize',16)
  259. ylabel(ax(1),'Y (cm)','FontSize',16)
  260. L=4;
  261. elseif o1==2 && o2 ==2
  262. set(cb(1:4),'value',0)
  263. set(cb(5),'value',1)
  264. set(cb(6),'value',0)
  265. set(eb(3:6),'enable','on')
  266. set(tb(3:6),'enable','on')
  267. set(eb(1:2),'enable','off')
  268. set(tb(1:2),'enable','off')
  269. set(tb(3),'String','Y min')
  270. set(tb(4),'String','Y max')
  271. set(tb(5),'String','Z min')
  272. set(tb(6),'String','Z max')
  273. xlabel(ax(1),'Y (cm)','FontSize',16)
  274. ylabel(ax(1),'Z (cm)','FontSize',16)
  275. L=5;
  276. elseif o1==2 && o2 ==3
  277. set(cb(6),'value',1)
  278. set(cb(1:5),'value',0)
  279. set(eb(3:6),'enable','on')
  280. set(tb(3:6),'enable','on')
  281. set(eb(1:2),'enable','off')
  282. set(tb(1:2),'enable','off')
  283. set(tb(3),'String','Z min')
  284. set(tb(4),'String','Z max')
  285. set(tb(5),'String','X min')
  286. set(tb(6),'String','X max')
  287. xlabel(ax(1),'X (cm)','FontSize',16)
  288. ylabel(ax(1),' Z (cm)','FontSize',16)
  289. L=6;
  290. end
  291. end
  292. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  293. % All of the code beyond this point, is individual 'if' statements that
  294. % check what type of measurement will be performed, then executes the
  295. % type of measurement with the given parameters.
  296. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  297. increment = str2double(get(eb(9),'string'));
  298.  
  299. if nargin == 1 && o1 == 2
  300. xyE = 0.208; %This is half diameter of probe (cm)
  301. zE = 0.18; %This is the length from sensitive area to probe tip on Z(cm)
  302. check = get(cb(10), 'value'); %Value of 'Removing SidetoSide' (
  303. %less accuracy but will be faster and will not move side to side)
  304.  
  305. Npp = str2double(get(eb(8),'string'));
  306. start
  307. %If 'Z' is checked
  308. if L==3
  309.  
  310. fileIDZ = fopen('Z_1D_MagFieldMeas.txt','wt');
  311. fprintf(fileIDZ,'Z,B,Bx,By,Bz\n');
  312. Zmin = str2double(get(eb(1),'string'));
  313. Zmax = str2double(get(eb(2),'string'));
  314.  
  315. step = 0;
  316. totalSteps = (Zmax-Zmin)/increment;
  317. z = Zmin:increment:Zmax;
  318. z = z + zE;
  319. nz = length(z);
  320. Bx = zeros(nz,1);
  321. By = zeros(nz,1);
  322. Bz = zeros(nz,1);
  323. B = zeros(nz,1);
  324.  
  325. for kk =1:nz
  326.  
  327. if check == 1
  328. F = FieldM(Npp,s1);
  329. Bz(kk)=F(3);
  330. By(kk)=F(2);
  331. Bx(kk)=F(1);
  332. else
  333. F = FieldM(Npp,s1);
  334. Bz(kk)=F(3);
  335. movem(s2,2,xyE);
  336. F = FieldM(Npp,s1);
  337. By(kk)=F(2);
  338. movem(s2,2,-xyE);
  339. movem(s2,1,xyE);
  340. F = FieldM(Npp,s1);
  341. Bx(kk)=F(1);
  342. movem(s2,1,-xyE);
  343. end
  344.  
  345.  
  346. fprintf('Step %d out of %d.\n', step, totalSteps);
  347.  
  348. step = step + 1;
  349.  
  350. movem(s2,3,-increment);
  351. hold on
  352. B(kk) = sqrt(Bx(kk).^2 + By(kk).^2 + Bz(kk).^2);
  353. plot(ax(1),z(1:kk),B(1:kk),'-k','linewidth',2)
  354. xlabel(ax(1),'Distance from the surface (cm)','FontSize',16)
  355. ylabel(ax(1),'B_0 (G)','FontSize',16)
  356. drawnow
  357. fprintf(fileIDZ,'%d,%d,%d,%d,%d\n',((step-1)*increment)+zE,B(kk),Bx(kk),By(kk),Bz(kk));
  358.  
  359. end
  360. movem(s2,3,increment);
  361. save Z_1D_Magnetic_field Bx By Bz B z
  362. fclose(fileIDZ);
  363. end
  364.  
  365. %If 'X' is checked
  366. if L==1
  367. Xmin = str2double(get(eb(1),'string'));
  368. Xmax = str2double(get(eb(2),'string'));
  369.  
  370. fileIDX = fopen('X_1D_MagFieldMeas.txt','wt');
  371. fprintf(fileIDX,'X,B,Bx,By,Bz\n');
  372.  
  373. step = 0;
  374. totalSteps = (Xmax-Xmin)/increment;
  375. x = Xmin:increment:Xmax;
  376.  
  377. nx = length(x);
  378. Bx = zeros(nx,1);
  379. By = zeros(nx,1);
  380. Bz = zeros(nx,1);
  381. B = zeros(nx,1);
  382. movem(s2,1,Xmin)
  383. for kk =1:nx
  384.  
  385. fprintf('Step %d out of %d.\n', step, totalSteps);
  386. step = step + 1;
  387.  
  388. if check == 1
  389. F = FieldM(Npp,s1);
  390. Bz(kk)=F(3);
  391. By(kk)=F(2);
  392. Bx(kk)=F(1);
  393. else
  394. F = FieldM(Npp,s1);
  395. Bz(kk)=F(3);
  396. movem(s2,2,xyE);
  397. F = FieldM(Npp,s1);
  398. By(kk)=F(2);
  399. movem(s2,2,-xyE);
  400. movem(s2,1,xyE);
  401. F = FieldM(Npp,s1);
  402. Bx(kk)=F(1);
  403. movem(s2,1,-xyE);
  404. end
  405. movem(s2,1,increment)
  406. hold on
  407. B(kk) = sqrt(Bx(kk).^2 + By(kk).^2 + Bz(kk).^2);
  408. plot(ax(1),x(1:kk),B(1:kk),'-k','linewidth',2)
  409. xlabel(ax(1),'X (cm)','FontSize',16)
  410. ylabel(ax(1),'B_0 (G)','FontSize',16)
  411. drawnow
  412. fprintf(fileIDX,'%d,%d,%d,%d,%d\n',(step-1)*increment,B(kk),Bx(kk),By(kk),Bz(kk));
  413. end
  414. movem(s2,1,-increment)
  415. save X_1D_Magnetic_field Bx By Bz B x
  416. fclose(fileIDX);
  417. end
  418.  
  419. %If 'Y' is checked
  420. if L==2
  421. Ymin = str2double(get(eb(1),'string'));
  422. Ymax = str2double(get(eb(2),'string'));
  423.  
  424. step = 0;
  425. totalSteps = (Ymax-Ymin)/increment;
  426. y = Ymin:increment:Ymax;
  427.  
  428. fileIDY = fopen('Y_1D_MagFieldMeas.txt','wt');
  429. fprintf(fileIDY,'Y,B,Bx,By,Bz\n');
  430.  
  431. ny = length(y);
  432. Bx = zeros(ny,1);
  433. By = zeros(ny,1);
  434. Bz = zeros(ny,1);
  435. B = zeros(ny,1);
  436. movem(s2,2,Ymin)
  437. for kk =1:ny
  438.  
  439. fprintf('Step %d out of %d.\n', step, totalSteps);
  440. step = step + 1;
  441. if check == 1
  442. F = FieldM(Npp,s1);
  443. Bz(kk)=F(3);
  444. By(kk)=F(2);
  445. Bx(kk)=F(1);
  446. else
  447. F = FieldM(Npp,s1);
  448. Bz(kk)=F(3);
  449. movem(s2,2,xyE);
  450. F = FieldM(Npp,s1);
  451. By(kk)=F(2);
  452. movem(s2,2,-xyE);
  453. movem(s2,1,xyE);
  454. F = FieldM(Npp,s1);
  455. Bx(kk)=F(1);
  456. movem(s2,1,-xyE);
  457. end
  458. movem(s2,2,-increment);
  459. hold on
  460. B(kk) = sqrt(Bx(kk).^2 + By(kk).^2 + Bz(kk).^2);
  461. plot(ax(1),y(1:kk),B(1:kk),'-k','linewidth',2)
  462. xlabel(ax(1),'Y (cm)','FontSize',16)
  463. ylabel(ax(1),'B_0 (G)','FontSize',16)
  464. drawnow
  465. fprintf(fileIDY,'%d,%d,%d,%d,%d\n',(step-1)*increment,B(kk),Bx(kk),By(kk),Bz(kk));
  466. disp('asd')
  467. end
  468. movem(s2,2,increment);
  469. save Y_1D_Magnetic_field Bx By Bz B y
  470. fclose(fileIDY);
  471. end
  472.  
  473. %If 'XY' is checked
  474. if L==4
  475. Xmin = str2double(get(eb(3),'string'));
  476. Xmax = str2double(get(eb(4),'string'));
  477. Ymin = str2double(get(eb(5),'string'));
  478. Ymax = str2double(get(eb(6),'string'));
  479. x = Xmin:increment:Xmax;
  480. y = Ymin:increment:Ymax;
  481. nx = length(x);
  482. ny = length(y);
  483. Bx = zeros(nx,ny);
  484. By = zeros(nx,ny);
  485. Bz = zeros(nx,ny);
  486. B = zeros(nx,ny);
  487. step = 0;
  488.  
  489. totalSteps = (Xmax-Xmin)*(Ymax-Ymin)/increment;
  490. fileIDXY = fopen('XY_1D_MagFieldMeas.txt','wt');
  491. fprintf(fileIDXY,'Y columns by X rows\n\n');
  492.  
  493. %This will write the XY data values into the text file.
  494. fprintf(fileIDXY,'X Values:');
  495. for xx = 0:(nx-1)
  496. fprintf(fileIDXY,'%d,',(Xmin+(xx*increment)));
  497. end
  498. fprintf(fileIDXY,'\n\n');
  499.  
  500. fprintf(fileIDXY,'Y Values:');
  501. for yy = 0:(ny-1)
  502. fprintf(fileIDXY,'%d,',(Ymin+(yy*increment)));
  503. end
  504. fprintf(fileIDXY,'\n\n');
  505.  
  506. for xx =1:nx
  507.  
  508. if xx == 1
  509. movem(s2,2,Ymin);
  510. movem(s2,1,Xmax);
  511. else
  512. movem(s2,2,-(Ymax-Ymin));
  513. end
  514. for yy = 1:ny
  515. if check == 1
  516. F = FieldM(Npp,s1);
  517. Bz(xx,yy)=F(3);
  518. By(xx,yy)=F(2);
  519. Bx(xx,yy)=F(1);
  520.  
  521. else
  522. F = FieldM(Npp,s1);
  523. Bz(xx,yy)=F(3);
  524. movem(s2,2,xyE);
  525. F = FieldM(Npp,s1);
  526. By(xx,yy)=F(2);
  527. movem(s2,2,-xyE);
  528. movem(s2,1,xyE);
  529. F = FieldM(Npp,s1);
  530. Bx(xx,yy)=F(1);
  531. movem(s2,1,-xyE);
  532. end
  533.  
  534. fprintf('Step %d out of %d. \n', step, totalSteps)
  535.  
  536. step = step+1;
  537.  
  538.  
  539. if yy==ny
  540. movem(s2,1,-increment);
  541. else
  542. movem(s2,2,increment);
  543. end
  544. B(xx,yy) = sqrt(Bx(xx,yy).^2 + By(xx,yy).^2 + Bz(xx,yy).^2);
  545. fprintf(fileIDXY,'%d,',B(xx,yy));
  546. end
  547. fprintf(fileIDXY,'\n');
  548.  
  549.  
  550. if xx>=2
  551. cla
  552. [Y,X] = meshgrid(y,x);
  553. size(Y)
  554. size(X)
  555. size(B(1:xx,:))
  556.  
  557. contour(X,Y,B,100)
  558. title('Magnetic Field B_o')
  559. xlabel(ax(1),'X (cm)','FontSize',16)
  560. ylabel(ax(1),'Y (cm)','FontSize',16)
  561. drawnow
  562. end
  563. if xx==ny
  564. movem(s2,2,-Ymax);
  565. end
  566.  
  567. end
  568.  
  569. save XY_2D_Magnetic_field01 Bx By Bz B y x
  570. fclose(fileIDXY);
  571. end
  572.  
  573. %If 'YZ'is checked
  574. if L==5
  575. Ymin = str2double(get(eb(3),'string'));
  576. Ymax = str2double(get(eb(4),'string'));
  577. Zmin = str2double(get(eb(5),'string'));
  578. Zmax = str2double(get(eb(6),'string'));
  579. z = Zmin:increment:Zmax;
  580. y = Ymin:increment:Ymax;
  581. z = z + zE;
  582. nz = length(z);
  583. ny = length(y);
  584. Bx = zeros(ny,nz);
  585. By = zeros(ny,nz);
  586. Bz = zeros(ny,nz);
  587. B = zeros(ny,nz);
  588. check = get(cb(10), 'value');
  589.  
  590. fileIDYZ = fopen('YZ_1D_MagFieldMeas.txt','wt');
  591. fprintf(fileIDYZ,'Y columns by Z rows\n\n');
  592.  
  593. fprintf(fileIDYZ,'Y Values:');
  594. for yy = 0:(ny-1)
  595. fprintf(fileIDYZ,'%d,',(Ymin+(yy*increment)));
  596. end
  597. fprintf(fileIDYZ,'\n\n');
  598.  
  599. fprintf(fileIDYZ,'Z Values:');
  600. for zz = 0:(nz-1)
  601. fprintf(fileIDYZ,'%d,',(Zmin+(zz*increment)));
  602. end
  603. fprintf(fileIDYZ,'\n\n');
  604.  
  605.  
  606. for kk =1:ny
  607. if kk == 1
  608. movem(s2,3,Zmin);
  609. movem(s2,2,Ymax);
  610. else
  611. movem(s2,3,-(Zmax-Zmin));
  612. end
  613. for ii = 1:nz
  614. if check == 1
  615. F = FieldM(Npp,s1);
  616. Bz(kk,ii)=F(3);
  617. By(kk,ii)=F(2);
  618. Bx(kk,ii)=F(1);
  619.  
  620. else
  621. F = FieldM(Npp,s1);
  622. Bz(kk,ii)=F(3);
  623. movem(s2,2,xyE);
  624. F = FieldM(Npp,s1);
  625. By(kk,ii)=F(2);
  626. movem(s2,2,-xyE);
  627. movem(s2,1,xyE);
  628. F = FieldM(Npp,s1);
  629. Bx(kk,ii)=F(1);
  630. movem(s2,1,-xyE);
  631. end
  632.  
  633. if ii==nz
  634. movem(s2,2,-increment);
  635. else
  636. movem(s2,3,increment);
  637. end
  638. B(kk,ii) = sqrt(Bx(kk,ii).^2 + By(kk,ii).^2 + Bz(kk,ii).^2);
  639. fprintf(fileIDYZ,'%d,',B(kk,ii));
  640. end
  641. fprintf(fileIDYZ,'\n');
  642.  
  643.  
  644. if kk>=2
  645. cla
  646. [Z,Y] = meshgrid(z,y);
  647. size(Y)
  648. size(Z)
  649. size(B(1:kk,:))
  650.  
  651. contour(Z,Y,B,100)
  652. title('Magnetic Field B_o')
  653. xlabel(ax(1),'Y (cm)','FontSize',16)
  654. ylabel(ax(1),'Z (cm)','FontSize',16)
  655. drawnow
  656. end
  657. if kk==ny
  658. movem(s2,3,-Zmax);
  659. end
  660.  
  661. end
  662.  
  663. save YZ_2D_Magnetic_field Bx By Bz B z y
  664. fclose(fileIDYZ);
  665. end
  666.  
  667. %If 'ZX' is checked
  668. if L==6
  669.  
  670. Zmin = str2double(get(eb(3),'string'));
  671. Zmax = str2double(get(eb(4),'string'));
  672. Xmin = str2double(get(eb(5),'string'));
  673. Xmax = str2double(get(eb(6),'string'));
  674. x = Xmin:increment:Xmax;
  675. z = Zmin:increment:Zmax;
  676. z = z + zE;
  677. nx = length(x);
  678. nz = length(z);
  679. Bx = zeros(nz,nx);
  680. By = zeros(nz,nx);
  681. Bz = zeros(nz,nx);
  682. B = zeros(nz,nx);
  683. check = get(cb(10), 'value');
  684.  
  685. fileIDZX = fopen('ZX_1D_MagFieldMeas.txt','wt');
  686. fprintf(fileIDZX,'Y columns by Z rows\n\n');
  687.  
  688. fprintf(fileIDZX,'Y Values:');
  689. for zz = 0:(nz-1)
  690. fprintf(fileIDZX,'%d,',(Zmin+(zz*increment)));
  691. end
  692. fprintf(fileIDZX,'\n\n');
  693.  
  694. fprintf(fileIDZX,'Z Values:');
  695. for xx = 0:(nx-1)
  696. fprintf(fileIDZX,'%d,',(Xmin+(xx*increment)));
  697. end
  698. fprintf(fileIDZX,'\n\n');
  699.  
  700.  
  701. for kk =1:nz
  702. if kk == 1
  703. movem(s2,1,Xmin);
  704. movem(s2,3,Zmax);
  705. else
  706. movem(s2,1,-(Xmax-Xmin));
  707. end
  708. for ii = 1:nx
  709. if check == 1
  710. F = FieldM(Npp,s1);
  711. Bz(kk,ii)=F(3);
  712. By(kk,ii)=F(2);
  713. Bx(kk,ii)=F(1);
  714. else
  715. F = FieldM(Npp,s1);
  716. Bz(kk,ii)=F(3);
  717. movem(s2,2,xyE);
  718. F = FieldM(Npp,s1);
  719. By(kk,ii)=F(2);
  720. movem(s2,2,-xyE);
  721. movem(s2,1,xyE);
  722. F = FieldM(Npp,s1);
  723. Bx(kk,ii)=F(1);
  724. movem(s2,1,-xyE);
  725. end
  726. if ii==nx
  727. movem(s2,3,-increment);
  728. else
  729. movem(s2,1,increment);
  730. end
  731. B(kk,ii) = sqrt(Bx(kk,ii).^2 + By(kk,ii).^2 + Bz(kk,ii).^2);
  732. fprintf(fileIDZX,'%d,',B(kk,ii));
  733. end
  734. fprintf(fileIDZX,'\n');
  735.  
  736. if kk>=2
  737. cla
  738. [X,Z] = meshgrid(x,z);
  739. size(X)
  740. size(Z)
  741. size(B(1:kk,:))
  742.  
  743. contour(X,Z,B,100)
  744. xlabel(ax(1),'Z (cm)','FontSize',16)
  745. ylabel(ax(1),'Y (cm)','FontSize',16)
  746. drawnow
  747. end
  748. if kk==nz
  749. movem(s2,1,-Xmax);
  750. end
  751. end
  752. save ZX_2D_Magnetic_field Bx By Bz B x z
  753. fclose(fileIDZX);
  754.  
  755. end
  756. stop
  757. end
  758.  
  759.  
  760. if o1==4 && o2==4
  761. start
  762. xyE = 0.208; %This is the diameter of the probe/2
  763. zE = 0.18; %This is the length from sensitive area to probe tip
  764. check = get(cb(10), 'value'); %Value of 'Removing SidetoSide' (
  765. %less accuracy but will be faster and will not move side to side)
  766. Npp = str2double(get(eb(8),'string'));
  767. Xmin = str2double(get(eb(14),'string'));
  768. Xmax = str2double(get(eb(15),'string'));
  769. Ymin = str2double(get(eb(10),'string'));
  770. Ymax = str2double(get(eb(11),'string'));
  771. Zmin = str2double(get(eb(12),'string'));
  772. Zmax = str2double(get(eb(13),'string'));
  773.  
  774.  
  775.  
  776.  
  777. x = Xmin:increment:Xmax;
  778. y = Ymin:increment:Ymax;
  779. z = Zmin:increment:Zmax;
  780. z=z+zE;
  781. nx = length(x);
  782. ny = length(y);
  783. nz = length(z);
  784. Bx = zeros(nx,ny,nz);
  785. By = zeros(nx,ny,nz);
  786. Bz = zeros(nx,ny,nz);
  787. B = zeros(nx,ny,nz);
  788. step = 0;
  789. recallMid = 1;
  790. for zz = 1:nz
  791.  
  792.  
  793. for xx =1:nx
  794. if recallMid == 1
  795. movem(s2,2,Ymin);
  796. movem(s2,1,Xmin);
  797. end
  798.  
  799. for yy = 1:ny
  800. recallMid = 2;
  801. if check == 1
  802. F = FieldM(Npp,s1);
  803. Bz(xx,yy,zz)=F(3);
  804. By(xx,yy,zz)=F(2);
  805. Bx(xx,yy,zz)=F(1);
  806. else
  807. F = FieldM(Npp,s1);
  808. Bz(xx,yy,zz)=F(3);
  809. movem(s2,2,xyE);
  810. F = FieldM(Npp,s1);
  811. By(xx,yy,zz)=F(2);
  812. movem(s2,2,-xyE);
  813. movem(s2,1,xyE);
  814. F = FieldM(Npp,s1);
  815. Bx(xx,yy,zz)=F(1);
  816. movem(s2,1,-xyE);
  817. end
  818.  
  819. step = step+1;
  820. if yy==ny && xx~=nx
  821. movem(s2,1,increment);
  822. movem(s2,2,-(Ymax-Ymin));
  823. elseif xx~=nx
  824. movem(s2,2,increment);
  825. end
  826. if (xx-1)==nx
  827. break;
  828. end
  829. end
  830. end
  831. B(:,:,zz) = sqrt(Bx(:,:,zz).^2 + By(:,:,zz).^2 + Bz(:,:,zz).^2);
  832.  
  833. movem(s2,1,-(Xmax-Xmin));
  834. movem(s2,3,-increment);
  835.  
  836. end
  837. save 3D_Magnetic_field01 Bx By Bz B y x
  838. stop
  839. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement