Matrix dimensions must agree

4 visualizaciones (últimos 30 días)
Areg Arzoomanian
Areg Arzoomanian el 1 de Dic. de 2019
Respondida: adeq123 el 12 de Dic. de 2019
%%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

Respuestas (1)

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by