My vectors are not the same length

7 次查看(过去 30 天)
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 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by