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 个评论

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.

请先登录,再进行评论。

 采纳的回答

I am not certain what you want to do.
Try this —
acq2.data = randi([0 5], 10, 5) % Create Matrix
acq2 = struct with fields:
data: [10×5 double]
idx = acq2.data(:,4) > 1 % Select Rows
idx = 10×1 logical array
1 1 1 0 1 1 0 1 0 1
empty_array = acq2.data(idx,:) % Assign Selected Rows To 'empty_array'
empty_array = 7×5
3 2 3 2 2 2 5 2 3 0 0 4 2 4 3 3 3 4 5 4 4 2 3 4 5 0 2 5 4 2 3 0 1 5 5
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 个评论

What I want to do is start collecting data from a certain row (iii) from column 4 of a data set when m(iii)>1 happens for the first time. I only want this to happen once because when it does happen for the first time I want that to be the starting data point and then from there I want 720000 points to be collected from the data set. So ideally I would have a new array that has data starting from row iii of column 4 and then ending at that row iii+720000 if that makes any sense at all?
I am not certain that I ujnderstand what you want to do.
If you want to collect every row after the first time column 4 is greater than 1, something like this would work:
acq2.data = randi([0 5], 10, 5) % Create Matrix
acq2 = struct with fields:
data: [10×5 double]
Show = acq2.data
Show = 10×5
3 5 1 1 0 1 4 4 4 2 4 5 0 0 1 1 1 5 1 0 3 4 3 5 1 0 0 3 5 5 2 1 5 0 3 2 1 4 1 0 1 2 4 5 5 5 3 2 4 0
start = find(acq2.data(:,4)>1,1,'first')
start = 2
empty_array = acq2.data(start:end,:)
empty_array = 9×5
1 4 4 4 2 4 5 0 0 1 1 1 5 1 0 3 4 3 5 1 0 0 3 5 5 2 1 5 0 3 2 1 4 1 0 1 2 4 5 5 5 3 2 4 0
.
n = 720000;
m = acq2.data(:,4);
empty_array2 = [];
for iii = 1:839272
if m(iii) > 1
empty_array2(iii) = m(iii);
end
if iii <= 839272
end
end
I basically was hoping to put a new column of data into an empty matrix. I want to start to collect this data when m(iii) first is greater than 1. However, this happens more than once so I am not sure how to do it so that I start this new data set when m(iii)>1 for the first time and continues to collect the data through the end of the set. If this doesn't help thank you for your help regardless.
I’m sorry, however I am now completely confused.
I have no idea what you want to do.
If you can clarify it, ideally with an example, I will see what I can do.
I just worked out a while loop which I think makes more sense but I am going to attempt to do another post since it is a very different format
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.

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by