Find rows in cell for each array between two values and create new cell with the values you just found

1 vue (au cours des 30 derniers jours)
Hello
For better understanding i attached an image of the problem.
I have two 8x5 cells n and p, which have the same size of arrays but different values in them. The arrays in the two cells countain all double values and each array in a cell has a different size.
I want tio create two new cells n_new and p_new which should contain values of the array itself.
x is the start value and y the end value. Im looking for a code wich goes to each array in cell n, looks for the start and the end and then writes the values which lie in between x and y to a new array in a new cell. So n_new{1,1} starts with the first value where n_{1,1} < x and ends with n{1,1}<y
This for each array so i thought it could work with a for loop like that, but the error says "Operator '<' is not supported for operands of type 'cell'."
for i =1:8
for u =1:8
row_start{i,u} = find(n<x,1);
row_end{i,u} = find(n<y,1);
n_new{i,u} =n{i,u}(row_start{i,u}:row_end{i,u})
end
end
I cant convert the whole cell two double. I found a way to do it, but it would be a 50 lines code for each array and im sure there is better way for the Problem.
Thanks in advance
Simon

Réponse acceptée

Stephen23
Stephen23 le 5 Jan 2021
Modifié(e) : Stephen23 le 5 Jan 2021
Using linear indexing to access the cell arrays only requires one loop:
n_new = cell(size(n));
for k = 1:numel(n)
idx = find(n{k}<x,1);
idy = find(n{k}<y,1);
n_new{k} = n{k}(idx:idy);
end

Plus de réponses (0)

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by