Unable to perform assignment because the left and right sides have a different number of elements.
1 view (last 30 days)
Show older comments
Hey everyone,
I have some acceleration data of experiments saved as a vector acc_g.
1) I now want to count the number of values in acc_g that are above +/- 1.5 g acceleration, which gives the variable k.
2) Then I want to determine these values, which gives acc_peak.
3) And at last, I want to display the row number of these maximum values and save them in the vector times_peak_acc. So I compare the acc_peak with the entire acceleration vector acc_g.
I get an error of "Unable to perform assignment because the left and right sides have a different number of elements." for step 3. However, the code works when k < 32??? What do I do wrong?
The length of the acc_g vector is 16342 x 1, so it is not smaller than 32...
Here is my code:
And thanks a lot in advance!
1)
k = 0;
for i = 1:length(acc_g)
if abs(acc_g(i,4)) >= 1.5
k = k+1;
end
end
2)
acc_peak = maxk(acc_g,k,'ComparisonMethod','abs');
3)
for n = 1:k
times_acc_peak(n) = find(acc_g==acc_peak(n));
end
0 Comments
Accepted Answer
Star Strider
on 3 Dec 2021
We will likely need to have the ‘acc_g’ matrix. (It can’t be a vector, since the reference to it in the first loop is to column 4.)
This runs without error —
acc_g = randn(1000,4); % Create Missing Data
% 1)
k = 0;
for i = 1:length(acc_g)
if abs(acc_g(i,4)) >= 1.5
k = k+1;
end
end
k % Display Result
% 2)
acc_peak = maxk(acc_g,k,'ComparisonMethod','abs');
% 3)
for n = 1:k
times_acc_peak(n) = find(acc_g==acc_peak(n));
end
times_acc_peak % Display Result
Note that ‘acc_peak’ is a (kx4) matrix, so that could be a problem, however it wasn’t one here.
.
6 Comments
More Answers (0)
See Also
Categories
Find more on Logical 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!