How to subplot inconsistent data in the loop?

조회 수: 1 (최근 30일)
muhammad choudhry
muhammad choudhry 2022년 1월 17일
편집: KSSV 2022년 1월 17일
Hi,
I am using the code below to plot the data ussing subplot, but the data is inconsistant and I am getting the error below. Can you guys help.
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in ABCD_HeadTimeStamps (line 22)
xm = [x x1 x2 x3];
Code:
files = ['F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_Head\Data_Raw\LaserSheet.xlsx'];
a = readtable(files);
x = a{:,3};
y = a{:,15};
files = ['F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_C\Data_Head\Data_Raw\LaserSheet.xlsx']
a = readtable(files);
x1 = a{:,3};
y1 = a{:,15};
files = ['F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_B\Data_Head\Data_Raw\LaserSheet.xlsx'];
a = readtable(files);
x2 = a{:,3};
y2 = a{:,15};
files = ['F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_A\Data_Head\Data_Raw\LaserSheet.xlsx'];
a = readtable(files);
x3 = a{:,3};
y3 = a{:,15};
% after obtaining the data, concatenate it into matrices
xm = [x x1 x2 x3];
ym = [y y1 y2 y3];
sheetlabel = 'DCBA'
figure(1)
for j = 1:4
subplot(2,2,j)
plot(xm(:,j),ym(:,j),'*')
%Spacing and griding
xlim([0 6])
ylim([0 600])
hold on
grid on
% Design Head
yy = 500;
line ([0,500],[yy,yy],'color','k','LineWidth',1);
txt = {'Design Head = 500 mm'};
text(1,560,txt)
xx = 5;
line ([xx,xx],[0,500],'color','k','LineWidth',1);
%Chart Representation
title(['DataLaserSheet-',sheetlabel(j)]);
xlabel('flowrate (l/s)');
ylabel('Head (mm))');
hold off
end
sgtitle('Outlet-110 mm')

채택된 답변

KSSV
KSSV 2022년 1월 17일
편집: KSSV 2022년 1월 17일
The dimensions of x, x1, etc are not same to join them.
% Demo
x = rand(2,1) ;
x1 = rand(4,1) ;
x2 = rand(3,1) ;
x =[x x1 x2]
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
You may consider the folloing code:
files = cell(4,1) ;
files{1} = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_Head\Data_Raw\LaserSheet.xlsx';
files{2} = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_C\Data_Head\Data_Raw\LaserSheet.xlsx';
files{3} = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_B\Data_Head\Data_Raw\LaserSheet.xlsx';
files{4} = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_A\Data_Head\Data_Raw\LaserSheet.xlsx';
figure(1)
for j = 1:4
a = readtable(files{j});
x = duration(a.(3));
y = a.(15);
subplot(2,2,j)
plot(x,y)
%Spacing and griding
xlim([0 6])
ylim([0 600])
hold on
grid on
% Design Head
yy = 500;
line ([0,500],[yy,yy],'color','k','LineWidth',1);
txt = {'Design Head = 500 mm'};
text(1,560,txt)
xx = 5;
line ([xx,xx],[0,500],'color','k','LineWidth',1);
%Chart Representation
title(['DataLaserSheet-',sheetlabel(j)]);
xlabel('flowrate (l/s)');
ylabel('Head (mm))');
hold off
end
sgtitle('Outlet-110 mm')
  댓글 수: 4
muhammad choudhry
muhammad choudhry 2022년 1월 17일
x = 152x1 (cell)
Y = 152x1 (double)
Attached are the excel files I am working with.
KSSV
KSSV 2022년 1월 17일
Edited the code.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by