Plooting pcolor plot for multiple matrix

조회 수: 10 (최근 30일)
Fiddin Ichwanul Alhaz
Fiddin Ichwanul Alhaz 2016년 8월 11일
댓글: MJ Thangaraj 2020년 3월 13일
Hi Guys,
I have 3 different huge matrix (as an example, in fact I have hundreds matrix), lets call it a1,a2,a3. I would like to plot them as pcolor. Each of them are positioned in a subplot. as you can see, it is pretty hectic to repeat the codes several times since I have hundreds of matrix. Is there any better way to do it? You can see my code below.
Thank you very much.
close all;
clear all;
clc
%call from ReadData script
ReadData;
disp ('2D view plotted')
%Plotting
rot_a1 = rot90(a1);
subplot (4,1,1)
figure (1);
pcolor(rot_a1); %plot raw data dari Tekscan to analyzed fooprint shape
set(gca,'fontsize',8);
caxis ([0 2000]); %Set up colorbar
x_range = 0:20:80;
set(gca,'XTick', x_range);
set(gca,'XTickLabel',num2cell(floor(x_range*5.08)));
y_range = 0:20:90;
set(gca,'YTick', y_range);
set(gca,'YTickLabel',num2cell(floor(y_range*5.08)));
colormap(jet (256));
ylabel('Longitudinal (mm)','fontsize',8);
xlabel('Lateral (mm)','fontsize',8);
shading('interp'); % control the color shading of the plot surface
% colorbar('horiz'); % plot a color bar
title('500 kPa, 10 kN','FontSize',9);
rot_a2 = rot90(a2);
subplot (4,1,2)
figure (1);
pcolor(rot_a2); %plot raw data dari Tekscan to analyzed fooprint shape
set(gca,'fontsize',8);
caxis ([0 2000]); %Set up colorbar
x_range = 0:20:80;
set(gca,'XTick', x_range);
set(gca,'XTickLabel',num2cell(floor(x_range*5.08)));
y_range = 0:20:90;
set(gca,'YTick', y_range);
set(gca,'YTickLabel',num2cell(floor(y_range*5.08)));
colormap(jet (256));
ylabel('Longitudinal (mm)','fontsize',8);
xlabel('Lateral (mm)','fontsize',8);
shading('interp'); % control the color shading of the plot surface
% colorbar('horiz'); % plot a color bar
title('500 kPa, 20 kN','FontSize',9);
rot_a3 = rot90(a3);
subplot (4,1,3)
figure (1);
pcolor(rot_a3); %plot raw data dari Tekscan to analyzed fooprint shape
set(gca,'fontsize',8);
caxis ([0 2000]); %Set up colorbar
x_range = 0:20:80;
set(gca,'XTick', x_range);
set(gca,'XTickLabel',num2cell(floor(x_range*5.08)));
y_range = 0:20:90;
set(gca,'YTick', y_range);
set(gca,'YTickLabel',num2cell(floor(y_range*5.08)));
colormap(jet (256));
ylabel('Longitudinal (mm)','fontsize',8);
xlabel('Lateral (mm)','fontsize',8);
shading('interp'); % control the color shading of the plot surface
% colorbar('horiz'); % plot a color bar
title('500 kPa, 30 kN','FontSize',9);
rot_a4 = rot90(a4);
subplot (4,1,4)
figure (1);
pcolor(rot_a4); %plot raw data dari Tekscan to analyzed fooprint shape
set(gca,'fontsize',8);
caxis ([0 2000]); %Set up colorbar
x_range = 0:20:80;
set(gca,'XTick', x_range);
set(gca,'XTickLabel',num2cell(floor(x_range*5.08)));
y_range = 0:20:90;
set(gca,'YTick', y_range);
set(gca,'YTickLabel',num2cell(floor(y_range*5.08)));
colormap(jet (256));
ylabel('Longitudinal (mm)','fontsize',8);
xlabel('Lateral (mm)','fontsize',8);
shading('interp'); % control the color shading of the plot surface
% colorbar('horiz'); % plot a color bar
title('500 kPa, 40 kN','FontSize',9);
  댓글 수: 1
KSSV
KSSV 2016년 8월 11일
What dimensions the matrices are? what is rot90? you need not to make that a huge attempt to plot it..it can be done with single plot command and a loop.

댓글을 달려면 로그인하십시오.

채택된 답변

Swathik Kurella Janardhan
Swathik Kurella Janardhan 2016년 8월 15일
As Dr. Siva Srinivas Kolukula mentioned, you can put the code to plot inside a loop and the matrices inside a cell vector and index the cell vector to plot each matrix inside the loop.
I modified your code for two matrices and initialized the matrices with sample values as below:
close all;
clear all;
clc
%call from ReadData script
% ReadData;
% Initialize two matrices with sample values
a1 = ones(10,10);
a2 = ones(20,20);
a = cell(2);
a{1} = a1; a{2} = a2;
disp ('2D view plotted')
for idx = 1:length(a)
%Plotting
% index cell vector for required matrix
rot_a1 = rot90(a{idx});
% use index to position the sub plot
subplot (4,1,idx)
figure (1);
pcolor(rot_a1); %plot raw data dari Tekscan to analyzed fooprint shape
set(gca,'fontsize',8);
caxis ([0 2000]); %Set up colorbar
x_range = 0:20:80;
set(gca,'XTick', x_range);
set(gca,'XTickLabel',num2cell(floor(x_range*5.08)));
y_range = 0:20:90;
set(gca,'YTick', y_range);
set(gca,'YTickLabel',num2cell(floor(y_range*5.08)));
colormap(jet (256));
ylabel('Longitudinal (mm)','fontsize',8);
xlabel('Lateral (mm)','fontsize',8);
shading('interp'); % control the color shading of the plot surface
% colorbar('horiz'); % plot a color bar
title('500 kPa, 10 kN','FontSize',9);
end

추가 답변 (1개)

Fiddin Ichwanul Alhaz
Fiddin Ichwanul Alhaz 2016년 10월 27일
Thank for the help Dr. Siva Srinivas Kolukula and Swathik Kurella Janardhan. Really appreciate it.
  댓글 수: 1
MJ Thangaraj
MJ Thangaraj 2020년 3월 13일
Hey Alhaz,
I'm currently working on Tekscan for tire-pavement intercation. Anyway I could contact you for a couple of question.
Thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by