Azzera filtri
Azzera filtri

My vectors are not the same length

9 visualizzazioni (ultimi 30 giorni)
Gabriela
Gabriela il 14 Set 2023
Commentato: Walter Roberson il 14 Set 2023
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 Commenti
dpb
dpb il 14 Set 2023
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 il 14 Set 2023
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.

Accedi per commentare.

Risposte (1)

Matt J
Matt J il 14 Set 2023
t=linspace(0,500,numel(L.actual_ver));

Community Treasure Hunt

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

Start Hunting!

Translated by