Missing figures in MATLAB script
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
louis ferreira
el 1 de Jul. de 2021
Comentada: Cris LaPierre
el 2 de Jul. de 2021
The following code is written to graph data and provide mean and standard deviation of data sets desired.
Each one works when in an individual script, but when they are all together, only the final plot plots. initially, all plots plotted fine, then the next day it decided not to.
the only difference with today was the addition of the 6th set of data to be plotted and analysed, which is now the only one that plots...
Each plot is separated by its own "figure(N)", which i thought should have prevented this from occuring.
clear all, clc, close all, warning('off', 'all'),
%T9: Attempt at periodic mechanical mirror tilt (screws were able to be
%tilted, both for x and y by roughly 3pi/2 rads, forward and then back)
%Load data CSV
filename9 = 'LF_BS_MECHTILT_T9.csv';
opt9 = detectImportOptions(filename9);
T9t = readtable(filename9, opt9);
firstdataline9 = opt9.DataLines(1);
T9t.LineNo = (1:height(T9t)).' + (firstdataline9 - 1);
T9t = standardizeMissing(T9t, inf, 'Datavariables', {'X1_um_', 'Y1_um_'});
T9 = rmmissing(T9t);
figure(1)
subplot(2,1,1);
plot((T9{:,{'ms'}})*1e-3 , T9{:,{'X1_um_','Y1_um_'}});
legend({'x1(um)', 'y1(um)'}, 'location', "best");
title('Test 9: Attempt at periodic mechanical mirror tilt (Delta t from human error)');
xlabel('Time (seconds)');
ylabel('Distance From Centre (microns)'); grid on; grid minor;
subplot(2,1,2);
plot((T9{:,{'ms'}})*1e-3 , T9{:,{'I1_V_'}});
legend({'Intensity (Volts)'}, 'location', "best");
title('Test 9 (I(V))')
xlabel('Time (seconds)');
ylabel('Intensity (Volts)');grid on, grid minor;
Nend9 = 9590; Mend9 = 17869;
Nend9 = find(T9.LineNo <= Nend9, 1, 'last')
T9.LineNo(Nend9)
Mend9 = find(T9.LineNo <= Mend9, 1, 'last')
T9.LineNo(Mend9)
Nrange9 = 1 : Nend9;
Mrange9 = Nend9+1:Mend9;
T9NCMX = mean(T9{Nrange9, {'X1_um_'}}, 'omitnan')
T9NCMY = mean(T9{Nrange9, {'Y1_um_'}}, 'omitnan')
T9NCSTDX = std(T9{Nrange9, {'X1_um_'}}, 'omitnan')
T9NCSTDY = std(T9{Nrange9, {'Y1_um_'}}, 'omitnan')
T9CMX = mean(T9{Mrange9, {'X1_um_'}}, 'omitnan')
T9CMY = mean(T9{Mrange9, {'Y1_um_'}}, 'omitnan')
T9CSTDX = std(T9{Mrange9, {'X1_um_'}}, 'omitnan')
T9CSTDY = std(T9{Mrange9, {'Y1_um_'}}, 'omitnan')
%{
Qualitatively: we see clear signs of reduced deviation magnitudes and duration in the Corrected data when compared to the uncorrected data.
Quantitatively:
For the uncorrected range, the beams mean position(x,y) = (-164.2um , -253um)
with standard-deviation(x,y)= (385.8um, 338.2um)
For our corrected range, mean-position(x,y)= (-13.3um, -11.2um)
with standard-deviation(x,y)= (85um, 84um)
Taking ratios of C/NC:
CMX/NCMX = 13.3/385.8 = 0.0345 = 3.45%
CMY/NCMY = 11.2/253.1 = 0.044 = 4.4%
CSTDX/NCSTDX = 85/385.8= 0.22 = 22%
CSTDY/NCSTDY= 84/338.2 = 0.248 = ~25%
%}
% T10: 1hour with OptiSlaps (consistency test)
%Correction applied after ~100seconds
filename10 = 'LF_BS_T10.csv';
opt10 = detectImportOptions(filename10);
T10t = readtable(filename10, opt10);
firstdataline10 = opt10.DataLines(1);
T10t.LineNo = (1:height(T10t)).' + (firstdataline10 - 1);
T10t = standardizeMissing(T10t, inf, 'Datavariables', {'X1_um_', 'Y1_um_'});
T10 = rmmissing(T10t);
figure(2)
subplot(2,1,1);
plot((T10{:,{'ms'}})*1e-3 , T10{:,{'X1_um_','Y1_um_'}});
legend({'x1(um)', 'y1(um)'}, 'location', "best");
title('Test 10: Attempt at periodic mechanical mirror tilt (Delta t from human error)');
xlabel('Time (seconds)');
ylabel('Distance From Centre (microns)'); grid on; grid minor;
subplot(2,1,2);
plot((T10{:,{'ms'}})*1e-3 , T10{:,{'I1_V_'}});
legend({'Intensity (Volts)'}, 'location', "best");
title('Test 10 (I(V))')
xlabel('Time (seconds)');
ylabel('Intensity (Volts)');grid on, grid minor;
Nend10 = 7254; Mend10 = 357062;
Nend10 = find(T10.LineNo <= Nend10, 1, 'last');
T10.LineNo(Nend10)
Mend10 = find(T10.LineNo <= Mend10, 1, 'last');
T10.LineNo(Mend10)
Nrange10 = 1 : Nend10;
Mrange10 = Nend10+1:Mend10;
%Stats, finds mean and standard deviation for the corrected and uncorrected
%ranges
T10NCMX = mean(T10{Nrange10, {'X1_um_'}}, 'omitnan')
T10NCMY = mean(T10{Nrange10, {'Y1_um_'}}, 'omitnan')
T10NCSTDX = std(T10{Nrange10, {'X1_um_'}}, 'omitnan')
T10NCSTDY = std(T10{Nrange10, {'Y1_um_'}}, 'omitnan')
T10CMX = mean(T10{Mrange10, {'X1_um_'}}, 'omitnan')
T10CMY = mean(T10{Mrange10, {'Y1_um_'}}, 'omitnan')
T10CSTDX = std(T10{Mrange10, {'X1_um_'}}, 'omitnan')
T10CSTDY = std(T10{Mrange10, {'Y1_um_'}}, 'omitnan')
%Finds mean and std ratio (C/NC) adn gives as percentage
T10RMX= T10CMX/T10NCMX*100
T10RMY= T10CMY/T10NCMY*100
T10RSTDX= T10CSTDX/T10NCSTDX*100
T10RSTDY= T10CSTDY/T10NCSTDY*100
%{
Qualitatively: We do not see much other than a general convergence to 0 of data points after the 74s mark.
Zooming in does show a far less sinusoidal oscilation, on x and y when correction is applied, however, some of the impacts were strong enough to still deviate the beam from centre by a large amount in the time it takes the FSM to react to a change.
%}
%T11: Single Marble Drop
%Load NC CSV
filename11a = 'LF_BS_NC1b_T11.csv';
opt11a = detectImportOptions(filename11a);
T11at = readtable(filename11a, opt11a);
firstdataline11a = opt11a.DataLines(1);
T11at.LineNo = (1:height(T11at)).' + (firstdataline11a - 1);
T11at = standardizeMissing(T11at, inf, 'Datavariables', {'X1_um_', 'Y1_um_'});
T11a = rmmissing(T11at);
%Load C CSV
filename11b = 'LF_BS_C1b_T11.csv';
opt11b = detectImportOptions(filename11b);
T11bt = readtable(filename11b, opt11b);
firstdataline11b = opt11b.DataLines(1);
T11bt.LineNo = (1:height(T11bt)).' + (firstdataline11b - 1);
T11bt = standardizeMissing(T11bt, inf, 'Datavariables', {'X1_um_', 'Y1_um_'});
T11b = rmmissing(T11bt);
figure(3)
subplot(2,1,1);
plot((T11a{:,{'ms'}})*1e-3 , T11a{:,{'X1_um_','Y1_um_'}}); hold on,
plot((T11b{:,{'ms'}})*1e-3 , T11b{:,{'X1_um_','Y1_um_'}}); hold off,
legend({'x1(um)', 'y1(um)'}, 'location', "best");
title('Test 10: Attempt at periodic mechanical mirror tilt (Delta t from human error)');
xlabel('Time (seconds)');
ylabel('Distance From Centre (microns)'); grid on; grid minor;
subplot(2,1,2);
plot((T11a{:,{'ms'}})*1e-3 , T11a{:,{'I1_V_'}}); hold on,
plot((T11b{:,{'ms'}})*1e-3 , T11b{:,{'I1_V_'}}); hold off,
legend({'Intensity (Volts)'}, 'location', "best");
title('Test 11 (I(V))')
xlabel('Time (seconds)');
ylabel('Intensity (Volts)');grid on, grid minor;
%Stats, finds mean and standard deviation for the corrected and uncorrected
%ranges
T11NCMX = mean(T11a{:, {'X1_um_'}}, 'omitnan')
T11NCMY = mean(T11a{:, {'Y1_um_'}}, 'omitnan')
T11NCSTDX = std(T11a{:, {'X1_um_'}}, 'omitnan')
T11NCSTDY = std(T11a{:, {'Y1_um_'}}, 'omitnan')
T11CMX = mean(T11b{:, {'X1_um_'}}, 'omitnan')
T11CMY = mean(T11b{:, {'Y1_um_'}}, 'omitnan')
T11CSTDX = std(T11b{:, {'X1_um_'}}, 'omitnan')
T11CSTDY = std(T11b{:, {'Y1_um_'}}, 'omitnan')
%Finds mean and std ratio (C/NC) adn gives as percentage
T11RMX= T11CMX/T11NCMX*100
T11RMY= T11CMY/T11NCMY*100
T11RSTDX= T11CSTDX/T11NCSTDX*100
T11RSTDY= T11CSTDY/T11NCSTDY*100
% T12: 3mins marble drops, ~90s NC + ~90s C
filename12 = 'LF_BS_T11_Marble.csv';
opt12 = detectImportOptions(filename12);
T12t = readtable(filename12, opt12);
firstdataline12 = opt12.DataLines(1);
T12t.LineNo = (1:height(T12t)).' + (firstdataline12 - 1);
T12t = standardizeMissing(T12t, inf, 'Datavariables', {'X1_um_', 'Y1_um_'});
T12 = rmmissing(T12t);
figure(4)
subplot(2,1,1);
plot((T12{:,{'ms'}})*1e-3 , T12{:,{'X1_um_','Y1_um_'}});
legend({'x1(um)', 'y1(um)'}, 'location', "best");
title('Test 10: Attempt at periodic mechanical mirror tilt (Delta t from human error)');
xlabel('Time (seconds)');
ylabel('Distance From Centre (microns)'); grid on; grid minor;
subplot(2,1,2);
plot((T12{:,{'ms'}})*1e-3 , T12{:,{'I1_V_'}});
legend({'Intensity (Volts)'}, 'location', "best");
title('Test 10 (I(V))')
xlabel('Time (seconds)');
ylabel('Intensity (Volts)');grid on, grid minor;
Nend12 = 9549; Mend12 = 9463;
Nend12 = find(T12.LineNo <= Nend12, 1, 'last');
T12.LineNo(Nend12)
Mend12 = find(T12.LineNo <= Mend12, 1, 'last');
T12.LineNo(Mend12)
Nrange12 = 1 : Nend12;
Mrange12 = Nend12+1:Mend12;
%Stats, finds mean and standard deviation for the corrected and uncorrected
%ranges
T12NCMX = mean(T12{Nrange12, {'X1_um_'}}, 'omitnan')
T12NCMY = mean(T12{Nrange12, {'Y1_um_'}}, 'omitnan')
T12NCSTDX = std(T12{Nrange12, {'X1_um_'}}, 'omitnan')
T12NCSTDY = std(T12{Nrange12, {'Y1_um_'}}, 'omitnan')
T12CMX = mean(T12{ 9463:17867 , {'X1_um_'}}, 'omitnan')
T12CMY = mean(T12{9463:17867, {'Y1_um_'}}, 'omitnan')
T12CSTDX = std(T12{9463:17867, {'X1_um_'}}, 'omitnan')
T12CSTDY = std(T12{9463:17867, {'Y1_um_'}}, 'omitnan')
%Finds mean and std ratio (C/NC) adn gives as percentage
T12RMX= T12CMX/T12NCMX*100
T12RMY= T12CMY/T12NCMY*100
T12RSTDX= T12CSTDX/T12NCSTDX*100
T12RSTDY= T12CSTDY/T12NCSTDY*100
%T13
% T13: 3mins marble drops, ~90s NC + ~90s C
filename13 = 'LF_BS_T12_MASS.csv';
opt13 = detectImportOptions(filename13);
T13t = readtable(filename13, opt13);
firstdataline13 = opt13.DataLines(1);
T13t.LineNo = (1:height(T13t)).' + (firstdataline13 - 1);
T13t = standardizeMissing(T13t, inf, 'Datavariables', {'X1_um_', 'Y1_um_'});
T13 = rmmissing(T13t);
figure(5)
subplot(2,1,1);
plot((T13{:,{'ms'}})*1e-3 , T13{:,{'X1_um_','Y1_um_'}});
legend({'x1(um)', 'y1(um)'}, 'location', "best");
title('Test 10: Attempt at periodic mechanical mirror tilt (Delta t from human error)');
xlabel('Time (seconds)');
ylabel('Distance From Centre (microns)'); grid on; grid minor;
subplot(2,1,2);
plot((T13{:,{'ms'}})*1e-3 , T13{:,{'I1_V_'}});
legend({'Intensity (Volts)'}, 'location', "best");
title('Test 10 (I(V))')
xlabel('Time (seconds)');
ylabel('Intensity (Volts)');grid on, grid minor;
Nend13 = 9616; Mend13= 9617;
Nend13 = find(T13.LineNo <= Nend13, 1, 'last');
T13.LineNo(Nend13)
Mend13 = find(T13.LineNo <= Mend13, 1, 'last');
T13.LineNo(Mend13)
Nrange13 = 1 : Nend13;
Mrange13 = Nend13+1:Mend13;
%Stats, finds mean and standard deviation for the corrected and uncorrected
%ranges
T13NCMX = mean(T13{Nrange13, {'X1_um_'}}, 'omitnan')
T13NCMY = mean(T13{Nrange13, {'Y1_um_'}}, 'omitnan')
T13NCSTDX = std(T13{Nrange13, {'X1_um_'}}, 'omitnan')
T13NCSTDY = std(T13{Nrange13, {'Y1_um_'}}, 'omitnan')
T13CMX = mean(T13{ 9617:17869 , {'X1_um_'}}, 'omitnan')
T13CMY = mean(T13{9617:17869, {'Y1_um_'}}, 'omitnan')
T13CSTDX = std(T13{9617:17869, {'X1_um_'}}, 'omitnan')
T13CSTDY = std(T13{9617:17869, {'Y1_um_'}}, 'omitnan')
%Finds mean and std ratio (C/NC) adn gives as percentage
T13RMX= T13CMX/T13NCMX*100
T13RMY= T13CMY/T13NCMY*100
T13RSTDX= T13CSTDX/T13NCSTDX*100
T13RSTDY= T13CSTDY/T13NCSTDY*100
%T14
clear all, clc, close all
filename14a = 'LF_BS_NC100g.csv';
opt14a = detectImportOptions(filename14a);
T14at = readtable(filename14a, opt14a);
firstdataline14a = opt14a.DataLines(1);
T14at.LineNo = (1:height(T14at)).' + (firstdataline14a - 1);
T14at = standardizeMissing(T14at, inf, 'Datavariables', {'X1_um_', 'Y1_um_'});
T14a = rmmissing(T14at);
%Load C CSV
filename14b = 'LF_BS_C100g.csv';
opt14b = detectImportOptions(filename14b);
T14bt = readtable(filename14b, opt14b);
firstdataline14b = opt14b.DataLines(1);
T14bt.LineNo = (1:height(T14bt)).' + (firstdataline14b - 1);
T14bt = standardizeMissing(T14bt, inf, 'Datavariables', {'X1_um_', 'Y1_um_'});
T14b = rmmissing(T14bt);
figure(6)
subplot(2,1,1);
plot((T14a{:,{'ms'}})*1e-3 , T14a{:,{'X1_um_','Y1_um_'}}); hold on,
plot((T14b{:,{'ms'}})*1e-3 , T14b{:,{'X1_um_','Y1_um_'}}); hold off,
legend({'x1(um)', 'y1(um)'}, 'location', "best");
title('Test 10: Attempt at periodic mechanical mirror tilt (Delta t from human error)');
xlabel('Time (seconds)');
ylabel('Distance From Centre (microns)'); grid on; grid minor;
subplot(2,1,2);
plot((T14a{:,{'ms'}})*1e-3 , T14a{:,{'I1_V_'}}); hold on,
plot((T14b{:,{'ms'}})*1e-3 , T14b{:,{'I1_V_'}}); hold off,
legend({'Intensity (Volts)'}, 'location', "best");
title('Test 11 (I(V))')
xlabel('Time (seconds)');
ylabel('Intensity (Volts)');grid on, grid minor;
%Stats, finds mean and standard deviation for the corrected and uncorrected
%ranges
T14NCMX = mean(T14a{:, {'X1_um_'}}, 'omitnan')
T14NCMY = mean(T14a{:, {'Y1_um_'}}, 'omitnan')
T14NCSTDX = std(T14a{:, {'X1_um_'}}, 'omitnan')
T14NCSTDY = std(T14a{:, {'Y1_um_'}}, 'omitnan')
T14CMX = mean(T14b{:, {'X1_um_'}}, 'omitnan')
T14CMY = mean(T14b{:, {'Y1_um_'}}, 'omitnan')
T14CSTDX = std(T14b{:, {'X1_um_'}}, 'omitnan')
T14CSTDY = std(T14b{:, {'Y1_um_'}}, 'omitnan')
%Finds mean and std ratio (C/NC) adn gives as percentage
T14RMX= T14CMX/T14NCMX*100
T14RMY= T14CMY/T14NCMY*100
T14RSTDX= T14CSTDX/T14NCSTDX*100
T14RSTDY= T14CSTDY/T14NCSTDY*100
any help would be greatly appreciated.
If i have missed out one of the relevant data files then please let me know.
Thank you.
2 comentarios
Jan
el 1 de Jul. de 2021
Editada: Jan
el 1 de Jul. de 2021
"then the next day it decided not to." - nope. "it" does not decide anything. Matlab does exactly what you instruct it to do.
"the only difference with today was the addition of the 6th" - please meantion, which ones is the 6th. Can I guess this detail?
Compare the current version with the one from your backup yesterday. Then the difference should get clear.
Cris LaPierre
el 1 de Jul. de 2021
Unable to find or open 'LF_BS_T10.csv'. Check the path and filename or file permissions.
Respuesta aceptada
Jan
el 1 de Jul. de 2021
Editada: Jan
el 1 de Jul. de 2021
There is this brute clearing line in the middle of your code:
clear all, clc, close all
Of course it clears all variables and closes all figures.
This clearing is not useful. Use functions to keep your workspace clean. The line on top of the code is even worse:
clear all, clc, close all, warning('off', 'all'),
clear all is a waste of time, because it removes all loaded functions from the memory and relaoding them from the slow disk takes a lot of time. But disabling all warnings is a shot in your knee. Don't do this! Warnings are the friend of the programmer.
7 comentarios
Cris LaPierre
el 2 de Jul. de 2021
If the figure already exists, the figure(n) will make that figure the current figure. If your next action is plotting to the figure, then the plot command replaces the current plot (if hold is off), or adds to the current axes (if hold is on).
This is a general rule of thumb. Some axes types behave differently, but since you use plot, this is the behavior you can expect with this script.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!