Essential MATLAB Usage Techniques
-
Accessing the fitting toolbox using
cftool -
Reading Excel data in MATLAB
% Store Excel file in MATLAB working directory (e.g., test.xlsx)
data = xlsread('test.xlsx'); % Import Excel data
plot(data(1,:), data(2,:)); % Plot with first row as x-data, second as y-data
- Understanding MATLAB bracket usage
- Curly braces
{}for cell array assignment:b{4}=[4];
- Plotting techniques
plot(imp(:,1), imp(:,2), 'ro'); % Red circles ('r'=red, 'o'=circle)
plot(imp(1:2,1), imp(1:2,2)); % Line between two points
% Multiple line segments
plot(imp(3:5,1), imp(3:5,2));
plot(imp(6:8,1), imp(6:8,2));
plot(imp(9:11,1), imp(9:11,2));
plot(imp(12:14,1), imp(12:14,2));
- Adding axis labels and titles
figure
plot(allElementPoint{1}, allElementPoint{2}, 'ro');
xlabel('x(λ)');
ylabel('y(λ)');
zlabel('z(z)');
title('XLamda YLamda Title');
- Dynamic text annotations
n = 12.34;
plot([0 2], [0 2]);
text(1, 1, sprintf('abcd=%0.4f', n));
% With variables
text(3, 4, sprintf('Element Count: %0.2f', element_sum));
- Contorlling numeric precision
format long % High precision display
pi
format short % Standard precision
- Adjustnig figure size
set(gcf, 'Position', [100, 100, 350, 280], 'color', 'w');
% [x_position, y_position, width, height]
- Variable assignment and special characters
- Reference MATLAB documentation for symbol usage
- Font customization
xlabel('u=sin\theta cos φ', 'Fontname', 'Times New Roman', 'Fontsize', figure_FontSize);
- Positioning axis labels
pos = axis;
xlabel('{\itu}=sin\theta cos φ', 'Fontname', 'Times New Roman',...
'Fontsize', 'position', [pos(2) 1.15*pos(3)]);
% Bold font
'FontWeight', 'bold'