1- function plotRefSLDHelper(data , noDelay )
2- % Helper function to make it easier to plot from event. Data is a struct
3- % with the plot data and noDelay indicates if draw should be delayed.
1+ function plotRefSLDHelper(data , noDelay , linearX , q4 , showErrorBar , showGrid , showLegend )
2+ % Helper function to make it easier to plot from event.
3+ %
4+ % - Data is a struct with the plot data.
5+ % - noDelay indicates if draw should be delayed.
6+ % - linearX indicates that the X axis should be linear scale instead of log.
7+ % - q4 indicates that the Y axis should plot Q^4.
8+ % - showErrorBars indicates that the error bar should be shown in the plot
9+ % - showGrid indicates that the grid should be shown in the plot
10+ % - showLegend indicates that the legend should be shown in the plot
411 %
512 % plotRefSLDHelper(data, false);
613 arguments
714 data
815 noDelay {logical } = true
16+ linearX {logical } = true
17+ q4 {logical } = true
18+ showErrorBar {logical } = true
19+ showGrid {logical } = false
20+ showLegend {logical } = true
921 end
10-
22+
1123 defaultState = ' on' ;
1224 s = warning();
1325 if any(strcmp({s .identifier }, ' MATLAB:Axes:NegativeDataInLogAxis' ))
@@ -19,33 +31,54 @@ function plotRefSLDHelper(data, noDelay)
1931
2032 % Plot the data.reflectivity
2133 subplot(1 ,2 ,1 );
22- set(gca ,' YScale' ,' log' ,' XScale' ,' log' );
34+ if linearX
35+ set(gca ,' YScale' ,' log' ,' XScale' ,' linear' );
36+ else
37+ set(gca ,' YScale' ,' log' ,' XScale' ,' log' );
38+ end
39+
40+ if showGrid
41+ set(gca ,' YGrid' ,' on' ,' XGrid' ,' on' );
42+ end
2343 hold on
2444 lines = cell(numberOfContrasts , 1 );
45+ mult = 1 ;
46+ q4Data = 1 ;
2547 for i = 1 : numberOfContrasts
2648 thisRef = data.reflectivity{i };
2749 thisData = data.shiftedData{i };
28- if i == 1
29- mult = 1 ;
30- else
50+ if i > 1 || q4
3151 mult = 2 ^(4 * i );
3252 end
33-
53+
54+ if q4 && data .dataPresent(i )
55+ q4Data = thisData(: ,1 ).^4 ;
56+ end
57+ mult = q4Data / mult ;
58+ refY = thisRef(: ,2 ) .* mult ;
3459 % If there is data present
3560 % plot it - size of data.shiftedData
3661 % will be [n x 3] if so
37- if data .dataPresent(i )
38- errorbar(thisData(: ,1 ),thisData(: ,2 )./mult ,thisData(: ,3 )./mult ,' .' ,' MarkerSize' ,2.5 );
62+ if data .dataPresent(i ) && showErrorBar
63+ dataX = thisData(: , 1 );
64+ dataY = thisData(: ,2 ) .* mult ;
65+ dataErr = thisData(: ,3 ) .* mult ;
66+ errorbar(dataX , dataY , dataErr , ' .' , ' MarkerSize' , 2.5 );
3967 end
4068
4169 % Plot the fit
42- lines{i } = plot(thisRef(: ,1 ),thisRef( : , 2 )./ mult , ' -' ,' LineWidth' ,2 );
70+ lines{i } = plot(thisRef(: ,1 ), refY , ' -' , ' LineWidth' , 2 );
4371
4472 end
45- legend([lines{: }], data.contrastNames{: });
73+ if showLegend
74+ legend([lines{: }], data.contrastNames{: });
75+ end
4676
4777 % Plot the SLDs
4878 subplot(1 ,2 ,2 );
79+ if showGrid
80+ set(gca ,' YGrid' ,' on' ,' XGrid' ,' on' );
81+ end
4982 hold on
5083 nColumns = size(data .sldProfiles , 2 );
5184 lines = cell(numberOfContrasts * nColumns , 1 );
@@ -85,7 +118,9 @@ function plotRefSLDHelper(data, noDelay)
85118 end
86119 end
87120 end
88- legend([lines{: }], names{: });
121+ if showLegend
122+ legend([lines{: }], names{: });
123+ end
89124 if noDelay
90125 drawnow limitrate ;
91126 end
0 commit comments