Matrix dimensions must agree

1 次查看(过去 30 天)
Areg Arzoomanian
Areg Arzoomanian 2019-12-1
回答: adeq123 2019-12-12
%%ARO 3220L Exp 7 Script
%%read dat in
% time=Kd02.eTime;
% CommPos=Kd02.CommandedPo;
% OutPos=Kd02.sEncoder1Pos;
% CommandedCounts = 1200;
time=plot1.eTime;
CommPos=plot1.CommandedPo;
OutPos=plot1.sEncoder1Pos;
CommandedCounts = 1200;
n=length(time);
%Find crossing points for Commanded and Response
%Signal crossing from Positive to negative assigned true or '1'
CommCrossIndexAll = and((CommPos > 0), not(circshift((CommPos > 0), 1))); CommCrossIndexAll(1) = 0;
OutCrossIndexAll = and((OutPos > 0), not(circshift((OutPos > 0), 1))); OutCrossIndexAll(1) = 0;
%Collects the index values of the crossing points
CrossIndex=find(OutCrossIndexAll);
%Collects the times of the crossing points
CommCrossTime = time(find(CommCrossIndexAll));
OutCrossTime = time(CrossIndex);
nComm = length(CommCrossTime); %Number of crossings in command
nOut = length(OutCrossTime); %Number of crossings in response
%Calculate lag times, two choices if crossing point count unequal
if nComm == nOut
lagtime = OutCrossTime - CommCrossTime;
else
lagtime = OutCrossTime - CommCrossTime(1:nComm-1); %ERROR IS IN THIS LINE <-----------------------------------------------
end
for i=1:nOut-1
ampOut(i) =max(OutPos(CrossIndex(i):CrossIndex(i+1)))...
-min(OutPos(CrossIndex(i):CrossIndex(i+1))); %Calculate response amplitudes
CommCycleTime(i)=OutCrossTime(i+1)-OutCrossTime(i); %Calculate Cycle time
end
CommFreq = CommCycleTime.^-1; %Calculate Frequency from Cycle time
magDb=20*log10(ampOut/CommandedCounts); %Calculate Bode Magnitude Response
%Create plots
subplot(2,1,1)
plot(time,CommPos,time,OutPos)
title('Control Surface Response Pd = 0.004')
xlabel('Time (s)')
ylabel('Counts')
subplot(2,1,2)
plot(CommFreq,magDb)
title('Bode Magnitude')
xlabel('Frequency (Hz)')
ylabel('MdB')
I get the error:
'Matrix dimensions must agree.
Error in ARO3220L_Exp7_script (line 34)
lagtime = OutCrossTime - CommCrossTime(1:nComm-1);'
Im not quite sure whats wrong with the code please help

回答(1 个)

adeq123
adeq123 2019-12-12
The length of the vectors mentioned in error does not match. You need trim the longer one to the size of shorter one.

类别

Help CenterFile Exchange 中查找有关 Spectral Estimation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by