Hello Valeria,
To plot intensity values located at specific positions as described, especially when the positions do not align with a regular grid, you can't directly use “imagesc” because “imagesc” assumes a regular, evenly spaced grid for plotting. Instead, you should consider using a scatter plot or creating a custom grid that maps your specific (x, y) positions to the intensity values and then interpolating between these points to create an image that can be displayed with “imagesc” or similar functions.
Given your requirement and the example data, here are some ways to plot the intensity values at their specified (x, y) positions using either a scatter plot approach or interpolation approach.
1. Scatter Plot Approach:
This approach directly plots each point with its intensity value represented by colour. This method is suitable if you’re okay with a non-continuous representation of your data.
I = [96 99 96 100 99 98; ...
x1 = [3.38 3.41 3.45 3.49 3.535 3.5738];
x2 = [4.35 4.46 4.47 4.49 4.60 4.66];
I_combined = [I(1,:), I(2,:)];
scatter(x, y, 40, I_combined, 'filled');
title('Intensity Values at Specific Positions');
Output:
2. Interpolation Approach:
If you prefer a continuous representation, you can interpolate the intensity values onto a regular grid and then use imagesc or similar functions. This approach is more complex and involves selecting an interpolation method that suits your data.
[xq, yq] = meshgrid(min(x):0.01:max(x), min(y):0.01:max(y));
Iq = griddata(x, y, I_combined, xq, yq, 'linear');
imagesc([min(x) max(x)], [min(y) max(y)], Iq);
title('Interpolated Intensity Image');
Output:
Both approaches serve different purposes: the scatter plot method shows discrete data points with their exact intensity values, while the interpolation approach creates a continuous image that approximates intensity values between the specified positions.
Please refer to the following links to know further about related queries:
- Imagesc – Display image with scaled colours (Mathworks documentation): https://in.mathworks.com/help/matlab/ref/imagesc.html?searchHighlight=imagesc&s_tid=srchtitle_support_results_1_imagesc
- Scatter plot (Mathworks documentation): https://in.mathworks.com/help/matlab/ref/scatter.html?searchHighlight=Scatter%20plot&s_tid=srchtitle_support_results_1_Scatter%20plot
- Non-uniform contour/imagesc/colorbar (File Exchange): https://in.mathworks.com/matlabcentral/fileexchange/65424-non-uniform-contourf-imagesc-colorbar
- Imagesc2(varargin) for enhanced control (File Exchange): https://in.mathworks.com/matlabcentral/fileexchange/52484-imagesc2-varargin
Hope this helps!