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

1 view (last 30 days)
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)')

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 25 Mar 2018
Edited: KALYAN ACHARJYA on 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 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 25 Mar 2018
Edited: KALYAN ACHARJYA on 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!