Why does my code produce a different graph every time I run it?

1 vue (au cours des 30 derniers jours)
Lara Severne
Lara Severne le 25 Mar 2018
Commenté : Lara Severne le 25 Mar 2018
I am currently trying to produce a graph of acceleration. I initially had 66000 samples, and cropped it to 20001:66000 as this is where the interesting data is. There are also 3 other sensors with the data in a matrix, acceleration is the last column in said matrix. To perform an analysis I wished to average every 460 points into 1, to reduce the white noise on an fft. The code for this section was provided in a separate question and I am unsure whether it is correct. After the averaging I am trying to plot this graph (altering number of samples to a time domain). However, every time I run my code the graph produced keeps changing and I cannot figure out why. Any help would be greatly appreciated. Code is as below.
LongTestArray = table2array(LongTest);
A = LongTestArray(20001:66000, 1:4);
M = mean(A);
A(:,3) = A(:,3) - M(:,3);
A(:,4) = A(:,4) - M(:,4);
B = A;
B = randi(9, 46000, 4); %Create Matrix
Ar = reshape(B, [], 4, 4600); % Reshape
% A_RMS = sqrt(mean(Br.^2, 3)); % Calculate RMS
X=Ar(:,4);
f = 43.5 ; % reduced from sample rate of 20000 due to averaged results
samples = 0:size(X, 1)-1 ;
t = samples/f ;
%plot column 1
plot(t, X(:, 1) ) grid on ;
hold on ;
title('Low Frequency Accelerometer Test 1')
xlabel('Time (s)') % x-axis label
ylabel('Voltage (V)')

Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 25 Mar 2018
Modifié(e) : KALYAN ACHARJYA le 25 Mar 2018
% In your code having a statement to create a random matrix, each execution it generates the different random matrix.
B = randi(9, 46000, 4)
  3 commentaires
KALYAN ACHARJYA
KALYAN ACHARJYA le 25 Mar 2018
Modifié(e) : KALYAN ACHARJYA le 25 Mar 2018
If B matrix is fixed in each execution, then only you will get same results.Do you have any fixed matrix value for B?
B = randi(maximum value element, no of rows, no of colm
Try this one
B = randi(1, 46000, 4); %It generates Unit Matrix
But I am not sure whether OK with your result or not.
Lara Severne
Lara Severne le 25 Mar 2018
okay perfect thanks so much for your help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by