Trimming data with for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Sydney Kehoe
am 8 Jun. 2021
Kommentiert: Star Strider
am 8 Jun. 2021
I am trying to write a code that will use a specific column of data to start filling a new array when m(iii)>1, however, it now only gives back the data in the new array when m(iii)>1 so i'm not sure how to fix it. I also want it to collect 720000 data points starting when that first m(iii)>1. Any help would be appreciated, thank you.
length = 720000;
m = acq2.data(:,4);
empty_array2 = zeros(size(length));
for iii = 1:length
if m(iii) > 1
empty_array2(iii) = acq2.data(iii);
end
if iii <= length
end
end
1 Kommentar
Gatech AE
am 8 Jun. 2021
Be careful naming variables after built-in functions. The "length" function returns the largest dimension of an input. Also, you have size(length) where length is defined as a scalar, so your empty_array2 variable is actually only 1 by 1 in size.
Akzeptierte Antwort
Star Strider
am 8 Jun. 2021
I am not certain what you want to do.
Try this —
acq2.data = randi([0 5], 10, 5) % Create Matrix
idx = acq2.data(:,4) > 1 % Select Rows
empty_array = acq2.data(idx,:) % Assign Selected Rows To 'empty_array'
This will create ‘empty_array’ with rows of ‘acq2.data’ with values in column 4 are greater than 1. It is probably easier (and more efficient) than the loop.
.
6 Kommentare
Star Strider
am 8 Jun. 2021
Great!
Please supply as many details in your new post as you can. A sample of the data you want to process would be important, as well as an example of the result you want.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!