フィルターのクリア

Matrix is returning zero when the values clearly shouldn't.

6 ビュー (過去 30 日間)
Sasha
Sasha 2024 年 1 月 28 日
編集済み: Stephen23 2024 年 1 月 28 日
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 = 16000×1
1.0e+46 * -Inf -0.0033 9.9778 0.0011 -1.4066 -0.0003 0.2531 0.0001 -0.0510 -0.0000
%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
k_highS125D2 = 16000×1
1.0e+46 * -Inf -0.0033 9.9778 0.0011 -1.4066 -0.0003 0.2531 0.0001 -0.0510 -0.0000
  2 件のコメント
Torsten
Torsten 2024 年 1 月 28 日
What matrix are you talking about ? I don't get a zero matrix (see above).
Stephen23
Stephen23 2024 年 1 月 28 日
編集済み: Stephen23 2024 年 1 月 28 日
"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]
ans = 4×1
1.0e+23 * 0 0.0000 0.0000 1.0000
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?

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2024 年 1 月 28 日
移動済み: Walter Roberson 2024 年 1 月 28 日
%% 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 = 16000×1 cell array
{[ -Inf]} {[-3.2904e+43]} {[ 9.9778e+46]} {[ 1.0980e+43]} {[-1.4066e+46]} {[-2.9835e+42]} {[ 2.5310e+45]} {[ 8.1093e+41]} {[-5.1010e+44]} {[-2.0395e+41]} {[ 9.6452e+43]} {[ 5.0770e+40]} {[-2.3043e+43]} {[-1.5654e+40]} {[ 5.6665e+42]} {[ 3.9080e+39]}
%mean(k_highS25D2)
n = numel(k_highS25D2)
n = 16000
nnz(cell2mat(k_highS25D2))
ans = 16000
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.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by