How to subplot inconsistent data in the loop?
조회 수: 1 (최근 30일)
이전 댓글 표시
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')
댓글 수: 0
채택된 답변
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]
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!