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

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)')

 채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 3월 25일
편집: KALYAN ACHARJYA 2018년 3월 25일

0 개 추천

% 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

So to change this would I need to simply reshape the original matrix? Wasn't made clear in original answer that this was for that purpose. Very new to coding so did not realise, sorry
KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 3월 25일
편집: KALYAN ACHARJYA 2018년 3월 25일
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.
okay perfect thanks so much for your help!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

질문:

2018년 3월 25일

댓글:

2018년 3월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by