Hi,
I called tiledlayout() to create a 3x2 figure containing 6 subplots. I used nexttile to navigate to next subplots. Notice that I already specificed which grid to plot in by putting the index argument like nexttile(n_target_grid). When I have generated the figure by running the script once, and then running it again (with some fixes applied) the following error would occur:
Index in position 1 exceeds array bounds. Index must not exceed 1.
Error in HW3_Ex2 (line 66)
If I manually clear the workspace, the script would run fine; however, I would like to know specifcially which variable or operation went wrong, and if there is a way to avoid repeatedly clearning the workspace everytime (especially since MATLAB suggested not to do to to improve efficiency). I suspect there is some kind of "cursor" used by the tiledlayout() that went out of bound. Is there a way to "return" it to the starting position, and let the new run of script overwrite what was in there already?
Below is the plotting part of the script:
DFC_square = FindFourierCoeff(clipped_y_square);
DFC_tri = FindFourierCoeff(clipped_y_tri);
DFC_para = FindFourierCoeff(clipped_y_para);
df = fs_uni / length(DFC_para);
frequencies = (0:length(DFC_para)-1) * df;
stem(frequencies, abs(real(DFC_square)));
title('Square Wave - Real Part (Amplitude)');
stem(frequencies, abs(real(DFC_tri)));
title('Triangular Wave - Real Part (Amplitude)');
stem(frequencies, abs(real(DFC_para)));
title('Parabolic Wave - Real Part (Amplitude)');
stem(frequencies, angle(DFC_square));
title('Square Wave - Phase');
ylabel('Phase (Radians)');
stem(frequencies, angle(DFC_tri));
title('Triangular Wave - Phase');
ylabel('Phase (Radians)');
stem(frequencies, angle(DFC_para));
title('Parabolic Wave - Phase');
ylabel('Phase (Radians)');
tiledlayout.Padding = 'compact';
tiledlayout.TileSpacing = spacing;
This is indeed part of a data analysis homework, but this question is not related to the core assessment of the homework but rather matlab usage, so I hope it's okay. Thanks to everyone.