Advertisement
Guest User

ugh

a guest
May 29th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 6.93 KB | None | 0 0
  1. clf
  2. clear
  3.  
  4. function [magField, magnetisation] = assignData(hysteresisType)
  5.     filename = uigetfile(["*.xls"],"C:\Users\oliverp\Desktop\Scilab Graphing Files", "Choose " + string(hysteresisType) + " file to be rebinned", %f)
  6.     data = readxls(filename)
  7.     datasheet = data(1)
  8.     magField = datasheet(2:$, 1)
  9.     magnetisation = datasheet(2:$, 2)
  10. endfunction
  11.  
  12. function [fieldSample1, magSample1, fieldSample2, magSample2, fieldSample3, magSample3] = splitData(xData, yData)
  13.     i = 1
  14.     j = 1
  15.     while( increasingField(xData, i) == %T ) then
  16.        if(xData == 0) then
  17.             fieldSample1(j) == %nan
  18.             magSample1(j) == %nan
  19.         end
  20.         fieldSample1(j) = xData(i)
  21.         magSample1(j) = yData(i)
  22.         i = i + 1
  23.         j = j + 1
  24.     end
  25.     disp('size of m1Inc = ' + string(j))
  26.     j = 1
  27.     while( increasingField(xData, i) == %F ) then
  28.         if(xData == 0) then
  29.             fieldSample2(j) == %nan
  30.             magSample2(j) == %nan
  31.         end
  32.         fieldSample2(j) = xData(i)
  33.         magSample2(j) = yData(i)
  34.         i = i + 1
  35.         j = j + 1
  36.     end
  37.     disp('size of m1Dec = ' + string(j))
  38.     j = 1
  39.     while( ( increasingField(xData, i) == %T ) & ( xData(i) ~= xData($) ) ) then
  40.         if(xData == 0) then
  41.             fieldSample3(j) = %nan
  42.             magSample3(j) = %nan
  43.         end
  44.  
  45.         fieldSample3(j) = xData(i)
  46.         magSample3(j) = yData(i)
  47.         i = i + 1
  48.         j = j + 1
  49.     end
  50.     disp('size of m2Inc = ' + string(j))
  51.     disp('fields segregated')
  52. endfunction
  53.  
  54. function fldInc = increasingField(magneticField, i)
  55.     if ( ( magneticField(i) == magneticField($) ) | ( magneticField(i) == magneticField(1) ) ) then
  56.         //disp('1 or end')
  57.         fldInc = %T
  58.     /*elseif ( (magneticField(i-1) > magneticField(i) ) & ( magneticField(i) == magneticField(i+1) ) ) then
  59.         fldInc = %T
  60.     elseif ( (magneticField(i-1) < magneticField(i) ) & ( magneticField(i) == magneticField(i+1) ) ) then
  61.         fldInc = %F*/
  62.     elseif  ( magneticField(i+1) < magneticField(i)  ) then
  63.         //disp('decreasing')
  64.         fldInc = %F
  65.     elseif ( magneticField(i+1) > magneticField(i) ) then
  66.         //disp('increasing')
  67.         fldInc = %T
  68.     end
  69. endfunction
  70.  
  71. function d = delta(xSpace, i) //finds spacing in array between the ith and i+1th component
  72.     if( xSpace(i) == xSpace($)) then
  73.         d = abs(xSpace(i - 1) - xSpace(i))
  74.     else
  75.         d = abs(xSpace(i + 1) - xSpace(i))
  76.     end
  77. endfunction
  78.  
  79. function k = closestDat2Bin( datField, rebinField, j ) // Finds closest datapoint to the rebin point
  80.     n = 1
  81.     diff = []
  82.     minVal = -1
  83.     minCol = -1
  84.     //disp("size of mField = " + string( size(datField, 1) ) )
  85.     for n = 1:size(datField, 1)  do
  86.         diff(n) = abs( datField(n) - rebinField(j) )
  87.     end
  88.     [minVal, minCol] = min(diff)
  89.     k = minCol
  90.     //disp(" k = " + string(k))
  91. endfunction
  92.  
  93. function i = lhsDat2Bin( datField, rebinField, j, k) //finds left-most datapoint that is still closer to rebin field j than j-1
  94.     if( j == 1) then
  95.         i = k
  96.     elseif (j ~= 1 ) then
  97.  
  98.         while( abs(magneticField(k-1) - x(j)) < abs(magneticField(k-1) - x(j-1)) )
  99.             k = k - 1
  100.         end
  101.         i = k
  102.         //disp(" i = " + string(i))
  103.     end
  104. endfunction
  105.  
  106. function yOut = rebinning(magneticField, magnetisation, x)
  107.     //yOut = zeros(size(x,2), 1)
  108.     yMag = zeros( size( x, 1 ), 1 )
  109.     for j = 1:(size(x, 1)-1) do
  110.         //disp('j = ' + string(j))
  111.         n = 0
  112.         i = 0
  113.  
  114.         k = closestDat2Bin( magneticField, x, j)
  115.        
  116.         if delta(magneticField, k) <= delta(x, 1) then //if measurement increment is smaller than rebinning increment
  117.             i =  lhsDat2Bin( magneticField, x, j, k)
  118.             while ( abs(magneticField(i) - x(j)) < abs(magneticField(i) - x(j+1)))  //while measurement field is closest to x(j) rebinned data point
  119.                 yMag(j) = yMag(j) + magnetisation(i)
  120.                 n = n + 1
  121.                 //disp(n)
  122.                 if( magneticField(i) ~= magneticField($) ) then
  123.                     i = i + 1
  124.                 else
  125.                     break
  126.                 end
  127.             end
  128.             if n ~= 0 then
  129.                 yMag(j) = yMag(j)/n
  130.             else
  131.                 yMag(j) = magnetisation(k)
  132.             end
  133.             //disp('yMag = ' + string(yMag(j)) )
  134.         else
  135.             if ( ~isnan(magnetisation(k)) ) then
  136.                yMag(j) = magnetisation(k)
  137.             end
  138.         end
  139.     end
  140.     j = j + 1
  141.     k = closestDat2Bin( magneticField, x, j)
  142.     yMag(j) = magnetisation(k)
  143.     yOut = yMag
  144. endfunction
  145.  
  146. // Assign arrays from excel files
  147. disp("Pick LCMO hysteresis file:")
  148. [xDataL, yDataL] = assignData("LCMO")
  149.  
  150. //disp('sheet assigned')
  151. disp("Pick YBCO hysteresis file:")
  152. [xDataY, yDataY] = assignData("YBCO")
  153.  
  154. disp("Pick YSL-1 hysteresis file:")
  155. [xDataYSL, yDataYSL] = assignData("YSL")
  156.  
  157. // Create a struct for each array to be rebinned
  158. LCMOhyst = struct('x1', ,'x2', , 'x3', ,'y1', ,'y2', ,'y3',  ,'sample', 'LCMO')
  159. [LCMOhyst.x1, LCMOhyst.y1, LCMOhyst.x2, LCMOhyst.y2, LCMOhyst.x3, LCMOhyst.y3] = splitData(xDataL, yDataL)
  160.  
  161. YBCOhyst = struct('x1', ,'x2', , 'x3', ,'y1', ,'y2', ,'y3',  ,'sample', 'YBCO')
  162. [YBCOhyst.x1, YBCOhyst.y1, YBCOhyst.x2, YBCOhyst.y2, YBCOhyst.x3, YBCOhyst.y3] = splitData(xDataY, yDataY)
  163.  
  164. YSLhyst = struct('x1', ,'x2', , 'x3', ,'y1', ,'y2', ,'y3',  ,'sample', 'YSL')
  165. [YSLhyst.x1, YSLhyst.y1, YSLhyst.x2, YSLhyst.y2, YSLhyst.x3, YSLhyst.y3] = splitData(xDataYSL, yDataYSL)
  166.  
  167. // Rebinning section
  168. x1 = 0.03:0.01:0.99
  169. disp('Rebinning part 1')
  170. y1L = rebinning( LCMOhyst.x1, LCMOhyst.y1, x1' )
  171. y1Y = rebinning( YBCOhyst.x1, YBCOhyst.y1, x1' )
  172. y1YSL = rebinning(YSLhyst.x1, YSLhyst.y1, x1' )
  173. disp('part 1 Completed')
  174.  
  175. x2 = 1:-0.01:-0.99
  176. disp('Rebinning part 2')
  177. y2L = rebinning( LCMOhyst.x2, LCMOhyst.y2, x2' )
  178. y2Y = rebinning( YBCOhyst.x2, YBCOhyst.y2, x2' )
  179. y2YSL = rebinning(YSLhyst.x2, YSLhyst.y2, x2' )
  180. disp('part 2 Completed')
  181.  
  182. x3 = -1:0.01:0.1
  183. disp('Rebinning part 3')
  184. y3L = rebinning( LCMOhyst.x3, LCMOhyst.y3, x3' )
  185. y3Y = rebinning( YBCOhyst.x3, YBCOhyst.y3, x3' )
  186. y3YSL = rebinning(YSLhyst.x3, YSLhyst.y3, x3' )
  187. disp('part 3 Completed')
  188.  
  189. //Concatenate sections of hysteresis into final rebinned data
  190. x = cat(1, x1', x2', x3')
  191. yLCMO = cat(1, y1L, y2L, y3L)
  192. yYBCO = cat(1, y1Y, y2Y, y3Y)
  193. yYSL = cat(1, y1YSL, y2YSL, y3YSL)
  194.  
  195. //Normalise the maximum values for manipulation
  196. //yYBCO = yYBCO * max(yLCMO)/max(yYBCO)
  197. //yYBCO = yYBCO * 0.5 * max(yLCMO)/max(yYBCO)
  198. //yYBCO = yYBCO * max(yYSL)/max(yYBCO)
  199. //yLCMO = yLCMO * 0.5 * max(yYSL)/max(yLCMO)
  200. //yLCMO = yLCMO * 1.504983389
  201. //yYSL = yYSL * max(yLCMO)/max(yYSL)
  202.  
  203. // Plot data
  204. plot(x, yLCMO, 'r')
  205. //plot(x, yYBCO, 'b')
  206. plot(x, yYSL, 'b')
  207. //plot(x, yYBCO + yLCMO, '-oblk')
  208. plot(x, yYSL - yLCMO, '-oblk')
  209. xlabel('Magnetic Field (T)', 'fontsize', 4) //x-axis label
  210. ylabel('Magnetisation (e5 A/m)', 'fontsize', 4) // y-axis label
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement