필터 지우기
필터 지우기

My vectors are not the same length

조회 수: 9 (최근 30일)
Gabriela
Gabriela 2023년 9월 14일
댓글: Walter Roberson 2023년 9월 14일
So, I'm working on a code for class and they're asking me to plot two variables that aren't the same length. My time vector is t=0:0.005:500 which is has a length of 1x100 while my other variables are 1x500. What should I do?
this is my code:
clear;
clc;
L=load("ver.mat");
t=0:0.005:500;
Ensembl_avg=mean(L.ver);
plot(t,Ensembl_avg);
hold on;
plot(t,L.actual_ver);
I've also provided the "ver.mat" file just in case.
  댓글 수: 2
dpb
dpb 2023년 9월 14일
load ver
whos
Name Size Bytes Class Attributes actual_ver 1x500 4000 double ans 1x32 64 char cmdout 1x33 66 char ver 100x500 400000 double
So, what is ver versus actual_ver?
If this is a homework assignment, there must have been instructions as to what was expected -- think we would have to see this assignment to have any klew about it...
Walter Roberson
Walter Roberson 2023년 9월 14일
t=0:0.005:500;
whos t
Name Size Bytes Class Attributes t 1x100001 800008 double
Not length 100.
T = 0 : 5 : 500;
whos T
Name Size Bytes Class Attributes T 1x101 808 double
That would be a lot closer to 100... but notice that it is length 101. 0 is divisible by 5; 5 is divisible by 5, 10 is divisible by 5... up to 500 exactly is divisible by 5. There (0:100)*5 is 101 entries not 100 -- you have to count the endpoints.

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

답변 (1개)

Matt J
Matt J 2023년 9월 14일
t=linspace(0,500,numel(L.actual_ver));

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by