im a little confused on how I can get this to work I've changed the index size and nothing seems to work can someone help me pls. I keep getting error "Index exceeds matrix dimensions." i get the error @ for i = 1:3 m(i) =(.25*out(i,6) - .5...

1 visualización (últimos 30 días)
clc close all dataTable = zeros(6,5); % matrix for n = 1:6 if n <= 3 fileName = ['trial',string(n),'.25kg.txt']; fileName = fileName(1) + fileName(2) + fileName(3); else fileName = ['trial',string(n),'.5kg.txt']; fileName = fileName(1) + fileName(2) + fileName(3); end % Use your data file here (keep it in the same folder): fid = fopen(fileName, 'r' ); fgets(fid); % to get rid of the first 2 lines. do not change! fgets(fid); n=1; datmat=[]; % Initialize an empty string while 1, a= fgetl(fid); % Read one line of data in at a time in the format of a STRING if n == 1, na=length(a);, end; if ~isstr(a), % If a is no longer a string, stop reading break; end; n=n+1; anum=eval(['[',a(2:na-1),']']); datmat=[datmat;anum]; % mas is the data matrix end
A=datmat(:,4);
if A>0
B=A+A(677);
else
B=A-A(677);
end
datmat(:,4) = B;
[N,M]=size(datmat); % Dimensions of the matrix
% Descriptions of the columes:
% M=1, the sample index, sample index starts from 0
% M=2, the real time in seconds
% M=3, the excitation signal
% the force conversion factor to physical units = ??
% M=4-6, the readings from encoders 1-3
% the encoder conversion factor to physical units = ??
%
% Algorithm for identifying the peaks of the motion
m=4; % Look at the first encoder
for n=1:N,
if datmat(n,m) ~= 0,
firstsign=sign(datmat(n,m));
ns=n;
break;
end
end
peak=[]; % The variable to hold the peak values
neak=[]; % The corresponding index of the peak value
numk=5; % Number of peaks to look for
for npk=1:numk,
for n=ns+1:N,
nsign=sign(datmat(n,m));
if nsign ~= firstsign,
ns2=n;
break;
else %if signs dont change find last peak
if n == N
ns2 = n;
end
end
end
[ak,nk]=max(abs(datmat(ns:ns2,m))); % ak is the peak value in the range ns:ns2, nk is its index
peak=[peak,ak*firstsign];
neak=[neak,ns+nk-1];
ns=ns2; % Get ready for next peak search
firstsign=nsign;
if ns >= N-1,
break;
end
end
figure
plot(datmat(:,1),datmat(:,m))
hold on
plot(neak-1,peak,'x')
xlabel('Time (s)');
ylabel('Encoder position');
legend('Response', 'Peaks')
t = datmat(neak,2);%time
p = t(4)-t(2); %period
d = log(peak(2)/peak(4)); %log decrement
c = (2*d)/p; %damping constant/mass
wd = (2*pi)/p; %damped frequency
wn = sqrt(wd^2 + c^2/4); %natural frequency
k = wn^2; %spring constant/m
s = d/(wn*p); %damping ratio
out(j,:) = [s,wn,wd,d,p,k,c,0] %place all variables in matrix for output
end
for i=1:3 m(i)=(.25*out(i,6) - .5*out(i+3,6))/(out(i+3,6)-out(i,6)); %calculate three mc values end
mc = mean(m); %mc = average of ratio values
out(1:3,8)= .25 + mc; % actual mass = mass added plus mass of the cart out(4:6,8)= .5 + mc;
out(:,6) = out(:,6).*out(:,8);%multiply k/m by mass to get final k value out(:,7) = out(:,7).*out(:,8);%multiply c/m by mass to get final c value
display(out)
  1 comentario
Walter Roberson
Walter Roberson el 19 de Sept. de 2018
Some of the code is missing. We do not know that out has at least 6 rows.
Also, it is not impossible that some of those variables you are storing are empty, resulting an an out matrix that is not at least 6 wide.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by