Matrix is returning zero when the values clearly shouldn't.
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I can't seem to figure this out. I am trying to divide a matrix (1600, 1) by a matrix (1600, 1) and when I call the rows individually I get the correct dividend. When I go to add them to the matrix; however, it always returned zero. I just want to divide the matrices and find the mean. Expiriment 1.2 is my initial approach and expiriment 1.1 is what I have been playing around with. (Yes I know the mean is commented out because it is not working)
%% Data Import high_S25_D2
% Importing the file
high_S25_D2 = readmatrix('HighSpringRateS2.5D2.txt');
% Separating columns
Displacement_1_highS25D2 = high_S25_D2(10:end,3);
Acceleration_1_highS25D2 = high_S25_D2(10:end,10);
mc = 0.1; % mass of cart in kg
m = 1.717 + mc; % mass in kg
% Expriment 1.1
k_highS25D2 = [];
mean = 0;
for n = 1:16000
solve = (m.*Acceleration_1_highS25D2(n,1))./Displacement_1_highS25D2(n,1); % spring rate calulation for highS25D2
%class(solve)
k_highS25D2 = [k_highS25D2; solve];
end
k_highS25D2
%k_highS25D2;
%mean(k_highS25D2)
%n = numel(k_highS25D2)
% Expriment 1.2
k_highS125D2 = m.*Acceleration_1_highS25D2./Displacement_1_highS25D2 % spring rate calulation for highS125D2
2 commentaires
Stephen23
le 28 Jan 2024
Modifié(e) : Stephen23
le 28 Jan 2024
"When I go to add them to the matrix; however, it always returned zero."
I do not see any zeros in any of the data that you displayed here.
Note the difference:
[0;eps(0);5;1e23]
Only one of those values is exactly zero. Which one is easy to recognise.
I presume that you are looking at "0.0000" and incorrectly assumed that it means exactly zero. Did you actually check that value in any way other than simply looking at it displayed with limited precision in the command window?
Réponses (1)
Walter Roberson
le 28 Jan 2024
Déplacé(e) : Walter Roberson
le 28 Jan 2024
%% Data Import high_S25_D2
% Importing the file
high_S25_D2 = readmatrix('HighSpringRateS2.5D2.txt');
% Separating columns
Displacement_1_highS25D2 = high_S25_D2(10:end,3);
Acceleration_1_highS25D2 = high_S25_D2(10:end,10);
mc = 0.1; % mass of cart in kg
m = 1.717 + mc; % mass in kg
% Expriment 1.1
k_highS25D2 = [];
mean = 0;
for n = 1:16000
solve = (m.*Acceleration_1_highS25D2(n,1))./Displacement_1_highS25D2(n,1); % spring rate calulation for highS25D2
%class(solve)
k_highS25D2 = [k_highS25D2; {solve}];
end
k_highS25D2
%mean(k_highS25D2)
n = numel(k_highS25D2)
nnz(cell2mat(k_highS25D2))
All of the entries are non-zero.
I suspect that you might be getting confused by the way that the data gets displayed by default. The default output format is "format short"; if you "format long" before looking at the data then you will see the actual results.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!