Unable to perform assignment because the left and right sides have a different number of elements.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Lisa Oswald
am 3 Dez. 2021
Kommentiert: Star Strider
am 4 Dez. 2021
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 Kommentare
Akzeptierte Antwort
Star Strider
am 3 Dez. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!