Error while Plotting Vectors
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello I am quit new to MatLab. I am trying to create a plot and i am reciving the following error:
Error using plot
Vectors must be the same length.
Error in Carrolllab5 (line 16)
plot(X,HZ2,'b--')
My Code:
Y = readtable('lab5data000.xlsx','Range','E1:AJ43');
HZ = table2array(Y);
HZ1 = HZ';
HZ2 = HZ1(:);
Wave = detrend(HZ);
for i=1:32
[pks] = findpeaks(Wave(:,i));
meanWH(i) = mean(pks);
end
mn = mean(meanWH);
WH = mn*2;
X = (0:1:42);
figure (1)
plot(X,HZ2,'b--')
xlabel('time(sec)')
ylabel('height (m)')
title('10 HZ Wave Data')
I'm still unsure of what needs to be changed X=(0:1:42) is inside the data set. I am unsure of what other vector would need to be the same length? Any advice would be much appreciated Thank You.
댓글 수: 1
dpb
2021년 3월 15일
X = (0:1:42);
figure (1)
plot(X,HZ2,'b--')
It'x X and HZ2 that must be same length -- what does
whos X HX2
show you about the two? We know that X will be 43 elements long, apparently HZ2 is something else instead.
If the point is to plot against ordinal position beginning at the origin instead of one, the general code would be
X = (0:numel(HZ2));
figure (1)
plot(X,HZ2,'b--')
While not really your problem;
Y = readtable('lab5data000.xlsx','Range','E1:AJ43');
HZ = table2array(Y);
HZ1 = HZ';
HZ2 = HZ1(:);
is a whole lot of unneeded machinations -- one could either use table addressing and use the data in Y directly which will already be column-oriented or if one does want an array, use readmatrix instead of readtable
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!