필터 지우기
필터 지우기

Error using plot. Vectors must be the same length

조회 수: 2 (최근 30일)
Jen Gruber
Jen Gruber 2017년 12월 7일
댓글: Jen Gruber 2017년 12월 7일
Can anyone help with this? I'm trying to do a timeseries plot of SST for 3 months and I keep getting the following error: Error using plot Vectors must be the same length. I ran a whos command and it looks like I have about 200 more data points for January than I do for the other two months. Is there a way to fix this?
YY=A(:,1); %year
MM=A(:,2); %month
DD=A(:,3); %day
hh=A(:,4); %hour
mm=A(:,5); %minute
WDIR=A(:,6); %Wind Direction (degree)
WSPED=A(:,7); %Wind Speed (m/s)
tmpc=A(:,14); %Air Temperature (C)
sst=A(:,15); %Sea Surface Temperature
indexjan=find(MM==01); %extract January
sst_Jan=sst(indexjan);%January SST
indexjun=find(MM==06);%extract June
sst_Jun=sst(indexjun);%June SST
indexsep=find(MM==09);%extract September
sst_Sep=sst(indexsep);%September SST
tmpc_Jan=tmpc(indexjan); %January Air Temperature
data_title='Buoy 46093, lat/lon: 36.690N 122.410W'; %Character string for Buoy information
%calculate decimal day:
decimal_hour=hh+(mm/60); %decimal hour
decimal_day=DD+(decimal_hour/24); %decimal day
figure
plot(decimal_day, sst_Jan,'b-')
hold on
plot(decimal_day, sst_Jun,'r-')
plot(decimal_day, sst_Sep,'g-')
grid on
axis([1 31 10 18])
set(gca,'XTick',1:1:31,'YTick',10:1:18)
ylabel('Sea Surface Temperature (C)')
xlabel('Decimal Day of Month')
legend('Jan 2008','Jun 2008','Sep 2008')
title(data_title)
Error using plot
Vectors must be the same length.
>> whos Name Size Bytes Class Attributes
decimal_day 7040x1 56320 double
sst_Jan 713x1 5704 double
sst_Jun 574x1 4592 double
sst_Sep 577x1 4616 double

답변 (1개)

KL
KL 2017년 12월 7일
Shouldn't you be using only the hours and minutes relevant to those respective months?
decimal_hour = hh(indexjan)+(mm(indexjan)/60)
and similarly for the other months? In that case, corresponding x and y data to plot would be of same length.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by