Search code examples
imagematlabvisualizationmatlab-figuresubplot

Set size of image


I have created an image which is an output of the imagesc function in MATLAB.

My problem: How do I display a larger image of a transposed matrix and a much smaller regular plot as a subplot?

I have tried the following code for myself but have not gone far. I'm looking for comments on what I have done and suggestions that I could use to arrive at my final goal.

figure(1);
hFig = figure(1);
set(hFig, 'Position', [100 100 500 500]);
subplot(2,1,1)
imagesc(normalized_matrix'),colormap(jet)
ax = gca;
ax.XLimMode = 'manual';
ax.XLim = [0e4 30e4];
ax.XTickLabelMode = 'manual';
ax.XTickLabel = {'0', '5', '10', '15', '20', '25', '30'};
xlabel('Time in Seconds')

subplot(2,1,2)
plot(force_resample)
ax1 = gca;
ax1.XLimMode = 'manual';
ax1.XLim = [0e4 30e4];
ax1.XTickLabelMode = 'manual';
ax1.XTickLabel = {''};
ax1.YLimMode = 'manual';
ax1.YLim = [0 2];
ylabel('Force in Newtons')
ax1.XLimMode = 'manual';
ax1.XLim = [0e4 30e4];
ax1.XTickLabelMode = 'manual';
ax1.XTickLabel = {'0', '5', '10', '15', '20', '25', '30'};
xlabel('Time in Seconds')

Solution

  • Assign more parts of the subplot grid to the image. e.g:

    %Sample Data
    normalized_matrix = [1:10; 11:20; 21:30; 31:40];
    force_resample = rand(4,40);
    
    subplot(3,1,1:2);   %using 2/3 part of the grid for the image
    imagesc(normalized_matrix); 
    
    subplot(3,1,3);     %using remaining 1/3 part of the grid for plot
    plot(force_resample);
    

    which gives:

    output