Borrar filtros
Borrar filtros

Error while Plotting Vectors

1 visualización (últimos 30 días)
John Carroll
John Carroll el 15 de Mzo. de 2021
Comentada: dpb el 15 de Mzo. de 2021
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 comentario
dpb
dpb el 15 de Mzo. de 2021
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

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by