필터 지우기
필터 지우기

Vectors must be the same lengths; plotting

조회 수: 4 (최근 30일)
alexr
alexr 2011년 5월 2일
댓글: Komal Kumawat 2020년 10월 2일
I have googled this to death, the common error was people looping arrays. I just have 2 simple sets and cant see where the error is.
simulated=[0.0000000 4.3830000 4.9470000 2.0180000 0.1761000 0.0162800 4.3650000 4.9540000 2.0170000 0.1760000 0.0162700 ]
actual= [0.0750000 4.0750000 4.7630000 3.5130000 0.5125000 0.1375000 2.6380000 4.5750000 4.8880000 1.5130000 0.3250000 ]
x = 0:0.0002:0.01;
plot(x, simulated, x, actual);
legend('Simulated', 'Actual')
ylabel('Current (mA)')
xlabel('Time ( mS )')
title('Current across R2 as a function of VS','FontSize',12)
  댓글 수: 4
alexr
alexr 2011년 5월 3일
Great thanks, I thought only the number of elements in the simulated length had to match the actual. It works now
waqas muhammad
waqas muhammad 2018년 1월 16일
can you please tell me how did you solve the problem of number of elements and how you made it equal?

댓글을 달려면 로그인하십시오.

답변 (1개)

Smith
Smith 2016년 10월 30일
You just need to modify variable x to match the size of variable simulated or variable actual.
simulated=[0.0000000 4.3830000 4.9470000 2.0180000 0.1761000 0.0162800 4.3650000 4.9540000 2.0170000 0.1760000 0.0162700 ]
actual= [0.0750000 4.0750000 4.7630000 3.5130000 0.5125000 0.1375000 2.6380000 4.5750000 4.8880000 1.5130000 0.3250000 ]
x = linspace(0,0.01,length(actual));
plot(x, simulated, x, actual);
legend('Simulated', 'Actual')
ylabel('Current (mA)')
xlabel('Time ( mS )')
title('Current across R2 as a function of VS','FontSize',12)
  댓글 수: 3
Jan
Jan 2016년 11월 14일
@assiya malik: Please do not post a new question as a comment to an answer, but open a new thread. Note that the problem is hidding inside "calculated by Runge Kutta 4 method" and not shown here. It does not matter how you define the variables before you redefine them by any computations.
Komal Kumawat
Komal Kumawat 2020년 10월 2일
%*********************************************************% %Defining the frequency vector and the mass matrix, %damping matrix, the stiffness matrix and the amplitude of %the excitation force. %*********************************************************% f=linspace(0,0.7,50); m=[1 0;0 2]; k=[2 -1;-1 1]; c=[0.002 -0.001;-0.001 0.001]; fi=[1;1]; %*********************************************************% %Calculating the amplitude and the phase for each frequency %defined by the frequency vector. %*********************************************************% for i = 1:50 omega(i)=2*pi*f(i); %omega in terms of frequency omega2(i)=omega(i)*omega(i); % squaring omega a11=-omega2(i)*m+k; % representing the left hand… a12=omega(i)*c; % matrix of the single matrix… a21=-omega(i)*c; % equation a22=-omega2(i)*m+k; a=[a11 a12;a21 a22]; b=inv(a); c1=[0;0;fi]; d(1,i)=b(1,:)*c1; d(2,i)=b(2,:)*c1; d(3,i)=b(3,:)*c1; d(4,i)=b(4,:)*c1; x(1,i)=sqrt(abs(d(1,i))^2+abs(d(3,i))^2); x(2,i)=sqrt(abs(d(2,i))^2+abs(d(4,i))^2); p(1,i)=atan(d(1,i)/d(3,i))*180/pi; if p(1,i)<0 % to check whether the angle is negative or not. p(1,i)=180+p(1,i); else
p(1,i)=p(1,i);
end
p(2,i)=atan(d(2,i)/d(4,i))*180/pi;
if p(2,i)<0
if d(4,i)<0
p(2,i) = -180 + p(2,i)
else
p(2,i)=180+p(2,i);
end
else
p(2,i)=p(2,i);
end
end
figure(1)
plot(f,x(1,:));grid
xlabel(Frequency)
ylabel(Amplitude of Mass 1)
figure(2)
plot(f,x(2,:));grid
xlabel(Frequency)
ylabel(Amplitude of Mass 2)
figure(3)
plot(f,p(1,:));grid
xlabel(Frequency)
ylabel(Phase of Mass 1)
figure(4)
plot(f,p(2,:));grid
xlabel(Frequency)
ylabel(Phase of Mass 2)
Why this shows error, please tell me the solution, actually this is my project

댓글을 달려면 로그인하십시오.

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by