Error Using Plot: Vectors Must Be The Same Length

조회 수: 4 (최근 30일)
Aphile
Aphile 2022년 8월 31일
편집: Matt J 2022년 8월 31일
Hi, I'm getting this error when trying to plot my 2 graphs: Vectors must be the same length. I am very new to matlab and I understand this is a common problem but couldn't figure out how to change my code so it works just by looking at other people's more complicated situations of the same error. It is a (22875x4 double)
This is my code (where DataPoints is the name of my file):
clc
Fs=1000
variable1=(DataPoints);
variable2=0.01:Fs/10000:length(variable1)*Fs/1000
variable3=(DataPoints);
figure(1);
plot(variable2,variable3)
variable4=variable1;
variable5=length(variable1);
variable6=Fs;
[P1,F1]=pwelch(variable4,variable5,variable6);
Figure(2);
Plot(F1,P1)
  댓글 수: 2
Torsten
Torsten 2022년 8월 31일
And do you get the same output for
numel(variable2)
numel(variable3)
?
The error message says: no. So change variable2 accordingly (e.g.
variable2 = linspace(0.01,numel(variable3),numel(variable3))
Aphile
Aphile 2022년 8월 31일
I just tried this and it says "Unrecognizable function or variable."

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

답변 (1개)

Matt J
Matt J 2022년 8월 31일
편집: Matt J 2022년 8월 31일
Check the lengths of the variables you are plotting:
whos variable2 variable3 P1 F1
There is no gaurantee that I can see, based on the code you've shown, that variable2 and variable3 would be the same length.
  댓글 수: 2
Aphile
Aphile 2022년 8월 31일
편집: Aphile 2022년 8월 31일
I don't think they are as this is data from a dynamic test and im trying to plot a psd as well as time-acceleration graph.
Matt J
Matt J 2022년 8월 31일
편집: Matt J 2022년 8월 31일
If they are not the same length, what does it mean to you to "plot" them? A plot consists of coordinate pairs (x,y). If the inputs are not vectors with the same number of elements, how can you create pairs?

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

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by