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')
更多回答(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!