Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clf
- clear
- function [magField, magnetisation] = assignData(hysteresisType)
- filename = uigetfile(["*.xls"],"C:\Users\oliverp\Desktop\Scilab Graphing Files", "Choose " + string(hysteresisType) + " file to be rebinned", %f)
- data = readxls(filename)
- datasheet = data(1)
- magField = datasheet(2:$, 1)
- magnetisation = datasheet(2:$, 2)
- endfunction
- function [fieldSample1, magSample1, fieldSample2, magSample2, fieldSample3, magSample3] = splitData(xData, yData)
- i = 1
- j = 1
- while( increasingField(xData, i) == %T ) then
- if(xData == 0) then
- fieldSample1(j) == %nan
- magSample1(j) == %nan
- end
- fieldSample1(j) = xData(i)
- magSample1(j) = yData(i)
- i = i + 1
- j = j + 1
- end
- //disp('size of m1Inc = ' + string(j))
- j = 1
- while( increasingField(xData, i) == %F ) then
- if(xData == 0) then
- fieldSample2(j) == %nan
- magSample2(j) == %nan
- end
- fieldSample2(j) = xData(i)
- magSample2(j) = yData(i)
- i = i + 1
- j = j + 1
- end
- //disp('size of m1Dec = ' + string(j))
- j = 1
- while( ( increasingField(xData, i) == %T ) & ( xData(i) ~= xData($) ) ) then
- if(xData == 0) then
- fieldSample3(j) == %nan
- magSample3(j) == %nan
- end
- fieldSample3(j) = xData(i)
- magSample3(j) = yData(i)
- i = i + 1
- j = j + 1
- end
- //disp('size of m2Inc = ' + string(j))
- disp('fields segregated')
- endfunction
- function fldInc = increasingField(magneticField, i)
- if ( ( magneticField(i) == magneticField($) ) | ( magneticField(i) == magneticField(1) ) ) then
- fldInc = %T
- /*elseif ( (magneticField(i-1) > magneticField(i) ) & ( magneticField(i) == magneticField(i+1) ) ) then
- fldInc = %T
- elseif ( (magneticField(i-1) < magneticField(i) ) & ( magneticField(i) == magneticField(i+1) ) ) then
- fldInc = %F*/
- elseif ( magneticField(i+1) < magneticField(i) ) then
- fldInc = %F
- elseif ( magneticField(i+1) > magneticField(i) ) then
- fldInc = %T
- end
- endfunction
- function d = delta(xSpace, i) //finds spacing in array between the ith and i+1th component
- if( xSpace(i) == xSpace($)) then
- d = abs(xSpace(i - 1) - xSpace(i))
- else
- d = abs(xSpace(i + 1) - xSpace(i))
- end
- endfunction
- function k = closestDat2Bin( datField, rebinField, j ) // Finds closest datapoint to the rebin point
- n = 1
- diff = []
- minVal = -1
- minCol = -1
- //disp("size of mField = " + string( size(datField, 1) ) )
- for n = 1:size(datField, 1) do
- diff(n) = abs( datField(n) - rebinField(j) )
- end
- [minVal, minCol] = min(diff)
- k = minCol
- //disp(" k = " + string(k))
- endfunction
- function i = lhsDat2Bin( datField, rebinField, j, k) //finds left-most datapoint that is still closer to rebin field j than j-1
- if( j == 1) then
- i = k
- elseif (j ~= 1 ) then
- while( abs(magneticField(k-1) - x(j)) < abs(magneticField(k-1) - x(j-1)) )
- k = k - 1
- end
- i = k
- //disp(" i = " + string(i))
- end
- endfunction
- function yOut = rebinning(magneticField, magnetisation, x)
- //yOut = zeros(size(x,2), 1)
- yMag = zeros( size( x, 1 ), 1 )
- for j = 1:(size(x, 1)-1) do
- //disp('j = ' + string(j))
- n = 0
- i = 0
- k = closestDat2Bin( magneticField, x, j)
- if delta(magneticField, k) <= delta(x, 1) then //if measurement increment is smaller than rebinning increment
- i = lhsDat2Bin( magneticField, x, j, k)
- while ( abs(magneticField(i) - x(j)) < abs(magneticField(i) - x(j+1))) //while measurement field is closest to x(j) rebinned data point
- yMag(j) = yMag(j) + magnetisation(i)
- n = n + 1
- //disp(n)
- if( magneticField(i) ~= magneticField($) ) then
- i = i + 1
- else
- break
- end
- end
- if n ~= 0 then
- yMag(j) = yMag(j)/n
- else
- yMag(j) = magnetisation(k)
- end
- //disp('yMag = ' + string(yMag(j)) )
- else
- if ( ~isnan(magnetisation(k)) ) then
- yMag(j) = magnetisation(k)
- end
- end
- end
- j = j + 1
- k = closestDat2Bin( magneticField, x, j)
- yMag(j) = magnetisation(k)
- yOut = yMag
- endfunction
- // Assign arrays from excel files
- disp("Pick LCMO hysteresis file:")
- [xDataL, yDataL] = assignData("LCMO")
- //disp('sheet assigned')
- disp("Pick YBCO hysteresis file:")
- [xDataY, yDataY] = assignData("YBCO")
- disp("Pick YSL-1 hysteresis file:")
- [xDataYSL, yDataYSL] = assignData("YSL")
- // Create a struct for each array to be rebinned
- LCMOhyst = struct('x1', ,'x2', , 'x3', ,'y1', ,'y2', ,'y3', ,'sample', 'LCMO')
- [LCMOhyst.x1, LCMOhyst.y1, LCMOhyst.x2, LCMOhyst.y2, LCMOhyst.x3, LCMOhyst.y3] = splitData(xDataL, yDataL)
- YBCOhyst = struct('x1', ,'x2', , 'x3', ,'y1', ,'y2', ,'y3', ,'sample', 'YBCO')
- [YBCOhyst.x1, YBCOhyst.y1, YBCOhyst.x2, YBCOhyst.y2, YBCOhyst.x3, YBCOhyst.y3] = splitData(xDataY, yDataY)
- // Rebinning section
- x1 = 0.03:0.01:0.99
- disp('Rebinning part 1')
- y1L = rebinning( LCMOhyst.x1, LCMOhyst.y1, x1' )
- y1Y = rebinning( YBCOhyst.x1, YBCOhyst.y1, x1' )
- disp('part 1 Completed')
- x2 = 1:-0.01:-0.99
- disp('Rebinning part 2')
- y2L = rebinning( LCMOhyst.x2, LCMOhyst.y2, x2' )
- y2Y = rebinning( YBCOhyst.x2, YBCOhyst.y2, x2' )
- disp('part 2 Completed')
- x3 = -1:0.01:0.1
- disp('Rebinning part 3')
- y3L = rebinning( LCMOhyst.x3, LCMOhyst.y3, x3' )
- y3Y = rebinning( YBCOhyst.x3, YBCOhyst.y3, x3' )
- disp('part 3 Completed')
- //Concatenate sections of hysteresis into final rebinned data
- x = cat(1, x1', x2', x3')
- yLCMO = cat(1, y1L, y2L, y3L)
- yYBCO = cat(1, y1Y, y2Y, y3Y)
- //Normalise the maximum values for manipulation
- yYBCO = yYBCO * max(yDataYSL)/max(yYBCO)
- yLCMO = yLCMO * max(yDataYSL)/max(yLCMO)
- // Plot data
- plot(x, yLCMO, 'r')
- plot(x, yYBCO, 'b')
- plot(x, yYBCO + yLCMO, '-oblk')
- plot(xDataYSL, yDataYSL, 'g')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement